Skip to content

Commit cc85b9d

Browse files
authored
Gracefully handle error conditions (#22)
* Gracefully handle empty and 'any' types in terraform * graceful reporting of errors/warnings * bicep changes mostly done * bicep working, pretty output * lint * lint * revert .golangci.yaml * remove pre-commit workflow (dead) * clean up pretty logs
1 parent d142128 commit cc85b9d

File tree

23 files changed

+491
-296
lines changed

23 files changed

+491
-296
lines changed

.github/workflows/pre-commit.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.golangci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,4 @@ issues:
246246
- noctx
247247
- wrapcheck
248248
- gocognit
249-
- cyclop
249+
- cyclop

cmd/bicep.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmd
22

33
import (
4-
"encoding/json"
54
"fmt"
65
"os"
76

@@ -42,17 +41,11 @@ func NewCmdBicep() *cobra.Command {
4241
}
4342

4443
func runBicepInput(cmd *cobra.Command, args []string) error {
45-
schema, err := bicep.BicepToSchema(args[0])
46-
if err != nil {
47-
return err
48-
}
44+
result := bicep.BicepToSchema(args[0])
4945

50-
bytes, err := json.MarshalIndent(schema, "", " ")
51-
if err != nil {
52-
return err
53-
}
46+
fmt.Print(result.PrettyDiags())
47+
fmt.Print(result.PrettySchema())
5448

55-
fmt.Println(string(bytes))
5649
return nil
5750
}
5851

cmd/helm.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmd
22

33
import (
4-
"encoding/json"
54
"fmt"
65

76
"github.com/massdriver-cloud/airlock/docs/helpdocs"
@@ -31,16 +30,10 @@ func NewCmdHelm() *cobra.Command {
3130
}
3231

3332
func runHelmInput(cmd *cobra.Command, args []string) error {
34-
schema, err := helm.HelmToSchema(args[0])
35-
if err != nil {
36-
return err
37-
}
33+
result := helm.HelmToSchema(args[0])
3834

39-
bytes, err := json.MarshalIndent(schema, "", " ")
40-
if err != nil {
41-
return err
42-
}
35+
fmt.Print(result.PrettyDiags())
36+
fmt.Print(result.PrettySchema())
4337

44-
fmt.Println(string(bytes))
4538
return nil
4639
}

cmd/opentofu.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmd
22

33
import (
4-
"encoding/json"
54
"fmt"
65
"os"
76

@@ -43,17 +42,11 @@ func NewCmdOpenTofu() *cobra.Command {
4342
}
4443

4544
func runOpenTofuInput(cmd *cobra.Command, args []string) error {
46-
schema, err := opentofu.TofuToSchema(args[0])
47-
if err != nil {
48-
return err
49-
}
45+
result := opentofu.TofuToSchema(args[0])
5046

51-
bytes, err := json.MarshalIndent(schema, "", " ")
52-
if err != nil {
53-
return err
54-
}
47+
fmt.Print(result.PrettyDiags())
48+
fmt.Print(result.PrettySchema())
5549

56-
fmt.Println(string(bytes))
5750
return nil
5851
}
5952

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/hashicorp/hcl/v2 v2.22.0
1212
github.com/massdriver-cloud/terraform-config-inspect v0.0.1
1313
github.com/spf13/cobra v1.8.1
14-
github.com/stretchr/testify v1.9.0
14+
github.com/stretchr/testify v1.10.0
1515
github.com/wk8/go-ordered-map/v2 v2.1.8
1616
github.com/xeipuuv/gojsonschema v1.2.0
1717
github.com/zclconf/go-cty v1.15.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
105105
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
106106
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
107107
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
108-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
109-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
108+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
109+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
110110
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
111111
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
112112
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=

0 commit comments

Comments
 (0)