http/codegen: wrap cli.ParseEndpoint error in generated CLI#3928
Conversation
The generated cmd/<svc>-cli/main.go contains:
return cli.ParseEndpoint(...)
which violates golangci-lint's wrapcheck linter when downstream projects
enable it. Wrap the error with fmt.Errorf("parse endpoint: %w", err)
in the cli_end template so generated code is wrapcheck-clean.
The fmt import is already declared in http/codegen/example_cli.go's
import specs and goimports retains it now that the template actually
uses it.
Updates the 5 client-*.golden files to match the new template output.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Thanks for cleaning this up, this is a nice little quality-of-life fix for generated CLIs. One thing I think this changes accidentally: the example client has an HTTP -> JSON-RPC fallback in I think either the fallback needs to unwrap/check the underlying error, or this template should preserve the existing |
|
Perfect, thank you! |
Summary
cli.ParseEndpointreturn value inhttp/codegen/templates/cli_end.go.tplwithfmt.Errorf("parse endpoint: %w", err)so the generated example CLI passesgolangci-lintwithwrapcheckenabledhttp/codegen/testdata/golden/Today the generated
cmd/<svc>-cli/main.godoesreturn cli.ParseEndpoint(...), which returns an error from another package without wrapping it.wrapcheckflags this on every freshgoa exampleoutput and downstream projects have to either disable the linter or post-process the generated file."fmt"is already in the import spec list inhttp/codegen/example_cli.go, so no additional source change is needed; goimports retains it now that the template referencesfmt.Errorf.Follows the spirit of #3541 / #3542 / #3548 / #3736 / #3927 (golangci-lint cleanup on generated code).
Test plan
go test ./http/codegen/...make testmake lint