Repository navigation
fix(go): fall back on empty error messages and prefix inferred messages with the error code - #215
Conversation
…es with the error code
There was a problem hiding this comment.
All reported issues were addressed across 16 files
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
Generator Snapshot TestingSnapshot tests are running. Snapshot results: https://github.com/speakeasy-api/openapi-generation-snapshots/issues/168#issuecomment-6903522371 |
There was a problem hiding this comment.
0 issues found across 11 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would auto-approve. Go error-message generation now treats empty messages as missing and prefixes inferred messages with a sibling code field; regenerated SDKs and snapshots confirm the bounded fix. The dismissed boolean-code finding is a deliberate scope limit, not a blocking tradeoff.
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack
View guided diff | Turn on auto-fix | Re-trigger cubic
speakeasybot
left a comment
There was a problem hiding this comment.
Auto-approved: review:bypass label applied by @TristanSpeakEasy. Required status checks still gate this merge.
Why
Follow-up to #202, which made Go typed errors build
Error()from a nested or inferred message field. That left two gaps for a common error envelope like:{"error": {"code": "rate_limit", "message": "slow down"}}!= nil(or returned a value field directly), so"message": ""madeerr.Error()return"". TypeScript, Python and C# all treat an empty message as missing and use their fallback.err.Error()(fmt.Errorf("...: %w", err),log.Print(err)). Before fix(go): read nested and inferred error messages in typed errors #202 the JSON dump includedcode; after it, logs only show the bare message, which makes failures harder to tell apart.What changed
Error()uses the existing fallback: the JSON dump, or"unknown error"for a top-level marked field. This applies to pointer,OptionalNullableand value fields, including union error members.messageorerror.message, nox-speakeasy-error-messagemarker) and the struct that holds it has a scalarcodesibling (string, integer, number or enum),Error()returns"<code>: <message>". An absent, null or emptycode(including an empty string-backed enum) falls back to the bare message.x-speakeasy-error-messageare left as they are apart from the empty check. The marker is an explicit choice of whatError()should say, so the generator does not add to it.Generated output for
{error: {code, message}}:Review SDKs (
zSDKs/sdk-go, andzSDKs/sdk-cli, which embeds the Go SDK):Error()bodies gain the empty check, andRequestTimeoutError(inferredmessagewith an integercode) now returns"<code>: <message>".Review notes
errors.As), but in GoError()is usually the only thing that reaches a log. I limited it to inferred messages so a marked field keeps its exact output.codeis considered. Fields likestatusortypeare not, to keep the inference narrow and predictable.err.Error()for Go SDKs whose errors have an inferred message plus acodefield. Inferred messages only reached Go in fix(go): read nested and inferred error messages in typed errors #202, so the exposure is limited to SDKs regenerated since then.Testing
go test ./pkg/generate/snapshots/ -run TestSnapGo: passed.TestSnapGoErrorMessageLeafTypesadds schemas and contract cases for an empty message (pointer,OptionalNullable, value and top-level marked), nested and top-levelcode+message(string, integer andOptionalNullablecode; code absent, null or empty) and a marked message with acodesibling. Updated the three other Go error snapshots for the new empty check.TARGET=primary make test-go: 773 passed. The 501x-speakeasy-errorscase now expects"501: an error occurred". AddedTestErrorMessageEmptyAndCode.TARGET=review make build-go: only theError()bodies listed above changed.TARGET=review make build-cli: only the sameError()bodies changed.make check-template-go,npm run formatandgolangci-lint run ./pkg/generate/snapshots/...: pass.make lint: golangci-lint reported a gofmt issue intemplates/perms.go, which this PR does not touch. Localgofmt -l(Go 1.26) reports the file as clean, so it looks like a local toolchain mismatch. Relying on CI for the full lint run.Public-safety check
.claude/skills/public-repo-communication/SKILL.md).git diff --check.Summary by cubic
Fixes two gaps in Go-generated
Error()bodies: empty string messages now fall back like missing ones, and inferred messages are prefixed with a siblingcodefield.Previously
"message": ""madeerr.Error()return an empty string; it now falls back to the JSON dump or"unknown error". Inferred messages (nox-speakeasy-error-messagemarker) that share a struct with a scalarcodenow return"<code>: <message>", so failures are easier to tell apart in logs. A string-backed enumcodewith an empty value falls back to the bare message instead of producing": <message>". Marked messages keep their exact output.Behavior changes
OptionalNullable, value, and union error members.codeis considered;statusandtypeare ignored.errors.As.err.Error()output for Go SDKs regenerated since fix(go): read nested and inferred error messages in typed errors #202 whose errors have an inferred message plus acodefield.Written for commit 14d9d7c. Summary will update on new commits.