fix(bundler): preserve inner error codes instead of double-wrapping#702
Merged
Conversation
…s INTERNAL Stop runDeployer, extractComponentValues, copyDataFiles, and collectComponentManifests from unconditionally wrapping structured errors with ErrCodeInternal. When the inner error already carries a proper code (e.g., ErrCodeInvalidRequest, ErrCodeTimeout), return it as-is so the API layer maps it to the correct HTTP status. Fixes #679
This comment was marked as resolved.
This comment was marked as resolved.
lalitadithya
approved these changes
Apr 28, 2026
Contributor
Coverage Report ✅
Coverage BadgeMerging this branch will increase overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. |
lockwobr
pushed a commit
that referenced
this pull request
Apr 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stop
bundler.Make()from clobbering inner structured error codes (e.g.,INVALID_REQUEST,TIMEOUT) withErrCodeInternal, so the API returns correct HTTP status codes andretryablevalues.Motivation / Context
POST /v1/bundlereturns HTTP 500 /INTERNAL/retryable: truefor request-validation failures raised inside deployers. The inner error already carriesErrCodeInvalidRequest, but the outer wrap inrunDeployeroverwrites it withErrCodeInternal. Clients that retry on 5xx hammer the server for errors that will never succeed.Fixes: #679
Related: N/A
Type of Change
Component(s) Affected
cmd/aicr,pkg/cli)cmd/aicrd,pkg/api,pkg/server)pkg/recipe)pkg/bundler,pkg/component/*)pkg/collector,pkg/snapshotter)pkg/validator)pkg/errors,pkg/k8s)docs/,examples/)Implementation Notes
At 4 call sites in
pkg/bundler/bundler.go(runDeployer,extractComponentValues,copyDataFiles,collectComponentManifests), replaced unconditionalerrors.Wrap(ErrCodeInternal, ...)with a conditional pattern: if the inner error is already a*errors.StructuredError, return it as-is to preserve its code; otherwise wrap withErrCodeInternalas before.This follows the existing CLAUDE.md rule: "Don't double-wrap errors that already have proper codes."
Testing
Added 3 new tests:
TestMake_PreservesInnerErrorCode— path-traversal component returnsErrCodeInvalidRequestTestMake_PreservesTimeoutFromExtractValues— cancelled context returnsErrCodeTimeoutTestBundleEndpointPathTraversalReturns400— HTTP integration: verifies 400 +INVALID_REQUEST+retryable: falsepkg/bundler coverage: 61.3% (no decrease)
Risk Assessment
Rollout notes: API clients that previously retried on these 500s will now see 400s. This is the correct behavior per the API contract — no migration needed.
Checklist
make testwith-race)make lint)git commit -S) — GPG signing info