Skip to content

Go: map HTTP 400 to validation (not api_error) - #482

Open
jeremy wants to merge 1 commit into
mainfrom
fix/go-400-validation-mapping
Open

Go: map HTTP 400 to validation (not api_error)#482
jeremy wants to merge 1 commit into
mainfrom
fix/go-400-validation-mapping

Conversation

@jeremy

@jeremy jeremy commented Jul 28, 2026

Copy link
Copy Markdown
Member

Problem

SPEC.md §6 prescribes 400 → validation to match the other five SDKs, but Go's checkResponse had no case http.StatusBadRequest, so 400 Bad Request fell through to the default arm and was mislabeled api_error. The SPEC self-tagged this as a [CONFLICT]/[static] carve-out with no conformance coverage.

Fix

  • Add case http.StatusBadRequest → CodeValidation (retryable: false) to go/pkg/basecamp/helpers.go. This is a code/message correction, not a retry-behavior change.
  • Resolve the SPEC carve-outs: mark the error-code table row, the mapping-algorithm step, the non-retryable-errors note, and Appendix D as [conformance]-verified; drop the stale "Go currently maps 400 to api_error" note.
  • Add a 400 → validation case to the shared conformance fixture conformance/tests/error-mapping.json and a 400 row to helpers_test.go.

Tests / Verify

  • helpers_test.go 400 row proven to fail pre-fix (api_error != validation).
  • The new fixture case is green across all five conformance runners (Go, Kotlin, TypeScript, Ruby, Python) and passes conformance-fixtures-check.

Part of the retry-contract follow-up (#456 / #460 / #461 / #476). Independent of the other two PRs in the series (no shared files).


Summary by cubic

Maps HTTP 400 to validation in the Go SDK to align with SPEC §6 and other SDKs. Adds conformance coverage and a unit test; 400 remains non-retryable.

  • Bug Fixes
    • Go: map 400 → validation in go/pkg/basecamp/helpers.go (retryable: false).
    • Tests: add 400 case to conformance/tests/error-mapping.json and helpers_test.go.
    • Spec: mark 400 mapping and non-retryable note as [conformance]; clarify mapping algorithm fallbacks.

Written for commit 28a3be8. Summary will update on new commits.

Review in cubic

Copilot AI review requested due to automatic review settings July 28, 2026 06:28
@jeremy jeremy added bug Something isn't working go spec Changes to the Smithy spec or OpenAPI conformance Conformance test suite labels Jul 28, 2026
@github-actions github-actions Bot added documentation Improvements or additions to documentation breaking Breaking change to public API and removed spec Changes to the Smithy spec or OpenAPI labels Jul 28, 2026
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

⚠️ Potential breaking changes detected:

  • Change in error mapping: HTTP 400 responses are now mapped to a new error code CodeValidation instead of the more general api_error. This constitutes a breaking change as it alters the contract for error handling.

Review carefully before merging. Consider a major version bump.

@jeremy jeremy added the spec Changes to the Smithy spec or OpenAPI label Jul 28, 2026
@jeremy

jeremy commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

Series — retry-contract follow-up (branch fresh off main, each independent):

#481 and #483 both touch go/templates/client.tmpl (disjoint regions, no textual conflict). Whichever merges second should be rebased and regenerated (make -C go generate); the merged tree passes the Go generated-drift gate.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns the Go SDK’s HTTP error-code mapping with SPEC.md §6 and the other SDKs by correctly classifying HTTP 400 as validation (instead of falling through to api_error). This closes a documented spec/implementation mismatch and adds conformance + unit-test coverage for the 400 case.

Changes:

  • Go: map http.StatusBadRequest (400) to CodeValidation in checkResponse.
  • Conformance: add a 400 → validation case to conformance/tests/error-mapping.json.
  • Spec + tests: update SPEC.md to remove the prior carve-out and add a Go unit test row for 400.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
SPEC.md Updates §6 error-code table/mapping algorithm and non-retryable notes to reflect 400→validation as conformance-verified.
go/pkg/basecamp/helpers.go Adds an explicit 400→CodeValidation branch in checkResponse.
go/pkg/basecamp/helpers_test.go Adds a 400 row to the checkResponse status→code/retryability table test.
conformance/tests/error-mapping.json Adds a conformance fixture asserting 400 maps to validation with retryable=false.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread SPEC.md Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Re-trigger cubic

SPEC §6 prescribes 400 -> validation to match the other five SDKs, but Go's
checkResponse had no 400 case, so it fell through to the default arm and
mislabeled 400 Bad Request as api_error. Add the missing case
(code=validation, http_status=400, retryable=false).

This resolves the [CONFLICT]/[static] carve-outs the SPEC carried for 400:
mark the error-code table row, the mapping-algorithm step, and the
non-retryable-errors note as [conformance]-verified, and drop the stale
"Go currently maps 400 to api_error" note.

Adds a 400 case to the shared error-mapping conformance fixture (verified
green across all five runners: Go, Kotlin, TypeScript, Ruby, Python) and a
400 row to helpers_test.go (proven to fail pre-fix: api_error != validation).
retryable stays false — this is a code/message correction, not a
retry-behavior change.

Follows the retry-contract program (#456/#460/#461/#476).
@jeremy
jeremy force-pushed the fix/go-400-validation-mapping branch from c5eb792 to 28a3be8 Compare July 28, 2026 06:50
Copilot AI review requested due to automatic review settings July 28, 2026 06:50
@github-actions github-actions Bot removed the spec Changes to the Smithy spec or OpenAPI label Jul 28, 2026
@jeremy

jeremy commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

Addressed the bot review:

  • [Copilot] Scoped the "[conformance]-verified" statement to steps 1–10 (explicitly enumerated statuses) and marked the two catch-all fallback steps (11: general 5xx; 12: any other non-mapped status) as [static].

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@jeremy jeremy added the spec Changes to the Smithy spec or OpenAPI label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaking change to public API bug Something isn't working conformance Conformance test suite documentation Improvements or additions to documentation go spec Changes to the Smithy spec or OpenAPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants