Kuadrant / Kuadrant/kuadrantctl

Enhance type error messages

Open
#97 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
8
Forks
18
PR merge metrics
No merged PRs in 30d

Description

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

```

Contributor guide

Open the contributing guide

Research direction

Start in pkg/gatewayapi/http_route.go, especially the HTTPRouteObjectMetaFromOAS and HTTPRouteRulesFromOAS entry points named in the examples, then trace their callers in cmd/generate_gatewayapi_httproute.go. Reproduce the two malformed x-kuadrant inputs and improve the resulting errors so they identify the invalid field and avoid exposing a full panic stack trace.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.