Skip to content

Enhance type error messages #97

@pehala

Description

@pehala

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions