Kuadrant / kuadrantctl

Kuadrant configuration command line utility
Apache License 2.0
6 stars 13 forks source link

Enhance type error messages #97

Open pehala opened 3 months ago

pehala commented 3 months ago

If you use wrong type in x-kuadrant extensions, kuadrantctl will panic and write cannot unmarshal object into Go struct field and the entire stacktrace, which makes it hard to deduce what exactly is wrong if you never encounter similar error in Go before and the message itself does not give that many pointers either.

Example messages: (Parent reference is not a list)

panic: json: cannot unmarshal object into Go struct field RouteObject.x-kuadrant.route.parentRefs of type []v1.ParentReference  goroutine 1 [running]: github.com/kuadrant/kuadrantctl/pkg/gatewayapi.HTTPRouteObjectMetaFromOAS(0xc000195b48?)     /home/phala/kuadrantctl/pkg/gatewayapi/http_route.go:15 +0x1b6 github.com/kuadrant/kuadrantctl/cmd.buildHTTPRoute(0xc0001d3290)     /home/phala/kuadrantctl/cmd/generate_gatewayapi_httproute.go:85 +0xa9 github.com/kuadrant/kuadrantctl/cmd.runGenerateGatewayApiHttpRoute(0xc00018d508, {0x182567a?, 0x4?, 0x182567e?})  /home/phala/kuadrantctl/cmd/generate_gatewayapi_httproute.go:59 +0x10f github.com/spf13/cobra.(*Command).execute(0xc00018d508, {0xc0000a79c0, 0x2, 0x2})    /home/phala/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0xaca github.com/spf13/cobra.(*Command).ExecuteC(0xc000276c08)     /home/phala/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff github.com/spf13/cobra.(*Command).Execute(0xc00013a130?)    /home/phala/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039 +0x13 main.main()  /home/phala/kuadrantctl/main.go:27 +0x4a

(Path level x-kuadrant is a list instead of a dict)

panic: json: cannot unmarshal array into Go struct field KuadrantOASPathObject.x-kuadrant of type utils.KuadrantOASPathExtension

goroutine 1 [running]:
github.com/kuadrant/kuadrantctl/pkg/gatewayapi.HTTPRouteRulesFromOAS(0xc0003342d0)
    /home/phala/kuadrantctl/pkg/gatewayapi/http_route.go:90 +0x57a
github.com/kuadrant/kuadrantctl/cmd.buildHTTPRoute(0xc0003342d0)
    /home/phala/kuadrantctl/cmd/generate_gatewayapi_httproute.go:91 +0x12f
github.com/kuadrant/kuadrantctl/cmd.runGenerateGatewayApiHttpRoute(0xc000423808, {0x182567a?, 0x4?, 0x182567e?})
    /home/phala/kuadrantctl/cmd/generate_gatewayapi_httproute.go:59 +0x10f
github.com/spf13/cobra.(*Command).execute(0xc000423808, {0xc0002fe740, 0x2, 0x2})
    /home/phala/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc000422008)
    /home/phala/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(0xc00013a130?)
    /home/phala/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039 +0x13
main.main()
    /home/phala/kuadrantctl/main.go:27 +0x4a