Skip to content

Slim AsertoError: single wrapped error, fixed grpc/http correlation, drop dead methods - #21

Merged
aserto-bot merged 4 commits into
mainfrom
slim-asertoerror-single-wrapped-error
Aug 24, 2026
Merged

Slim AsertoError: single wrapped error, fixed grpc/http correlation, drop dead methods#21
aserto-bot merged 4 commits into
mainfrom
slim-asertoerror-single-wrapped-error

Conversation

@gertd

@gertd gertd commented Aug 24, 2026

Copy link
Copy Markdown
Member

Summary

  • Fixes a live bug: Copy() shallow-copied the errs []error slice, letting siblings derived from the same parent share a backing array and silently corrupt each other's wrapped error once append had slack. Replaced errs []error with a single wrapped error field, which removes the aliasing by construction. azm already hits this pattern via nested Err() calls, so this isn't theoretical.
  • Fixes broken grpc↔HTTP status correlation: GRPCStatus() never wrote HTTPCode into the errdetails.ErrorInfo metadata that CustomErrorHandler reads back, so the one thing this package exists to provide only worked because topaz's gerr_middleware.go hand-rolled it a second time. Added ErrorInfo() and fixed GRPCStatus() to be the single source of truth.
  • Fixes singleton mutation: FromGRPCStatus no longer mutates the registered singleton *AsertoError in place — it copies first.
  • Removes dead code: Int/Int32/Int64/Bool/Duration/Time/FromReader/Interface/SameAs/Equals/WithGRPCStatus/WithHTTPStatus — zero real call sites across go-directory, topaz, and azm (verified by cloning and grepping all three). WithGRPCStatus's one usage in topaz (topazd/authorizer/impl/identity.go) is better served by a dedicated sentinel error than an override.
  • Renames StatusCodeGRPCCode for clarity.

This branch was rebased on top of the inner-error/formatting fixes already on main (Fields() recursion into inner errors, .Msg()-before-cause ordering, errors.As-based traversal) — it builds on those, doesn't touch them.

Full design rationale and downstream sequencing notes are in DESIGN.md.

Breaking changes for downstream consumers

topaz and azm will need updates wherever they:

  • read .StatusCode (now .GRPCCode)
  • call .WithGRPCStatus, .WithHTTPStatus, .SameAs, or cerr.Equals
  • chain .Err() more than once expecting accumulation (each .Err() now replaces rather than appends — only the test suite here exercised that, no downstream repo does)

Test plan

  • go build ./...
  • go vet ./...
  • gofmt -l . clean
  • go test ./... -race passes
  • Manually reproduced and verified the fix for the Copy() aliasing bug (siblings derived from a 3-deep error chain now stay independent)
  • Manually reproduced and verified the fix for the FromGRPCStatus singleton mutation
  • Verified Fields() still recurses into inner AsertoErrors under the new single-wrapped-error model

🤖 Generated with Claude Code

gertd and others added 3 commits August 24, 2026 14:21
…drop dead methods

Rebased on top of the concurrent inner-error/formatting fixes (Fields()
recursion, Msg-before-cause ordering, errors.As-based traversal) already
on main; this does not touch those, it builds on them.

Copy() shallow-copied the errs slice, letting siblings derived from the
same parent share a backing array and silently corrupt each other's
wrapped error once append had slack (azm already hits this pattern via
nested Err() calls). Replacing errs []error with a single wrapped error
removes the aliasing by construction. Fields()'s recursion into inner
AsertoErrors is preserved, adapted to the single wrapped field.

GRPCStatus() never wrote HTTPCode into the ErrorInfo metadata that
CustomErrorHandler reads back, so the grpc<->HTTP status correlation this
package exists for only worked because topaz's gerr_middleware hand-rolled
it a second time. Added ErrorInfo()/fixed GRPCStatus() to be the single
source of truth. FromGRPCStatus also no longer mutates the registered
singleton in place.

Removed Int/Int32/Int64/Bool/Duration/Time/FromReader/Interface/SameAs/
Equals/WithGRPCStatus/WithHTTPStatus: zero real call sites across
go-directory, topaz, and azm. WithGRPCStatus's one usage in topaz is
better served by a dedicated sentinel error than an override.

Renamed StatusCode -> GRPCCode for clarity. Downstream repos need updates
for the rename and removed methods; DESIGN.md has the full rationale and
sequencing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Gert Drapers <1533850+gertd@users.noreply.github.com>
Signed-off-by: Gert Drapers <1533850+gertd@users.noreply.github.com>
@coveralls

coveralls commented Aug 24, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 32731463535

Coverage increased (+4.1%) to 68.465%

Details

  • Coverage increased (+4.1%) from the base build.
  • Patch coverage: 6 uncovered changes across 1 file (46 of 52 lines covered, 88.46%).
  • 19 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
errors.go 52 46 88.46%

Coverage Regressions

19 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
errors.go 19 78.87%

Coverage Stats

Coverage Status
Relevant Lines: 241
Covered Lines: 165
Line Coverage: 68.46%
Coverage Strength: 0.76 hits per line

💛 - Coveralls

Signed-off-by: Gert Drapers <1533850+gertd@users.noreply.github.com>
@aserto-bot
aserto-bot merged commit 21f43c9 into main Aug 24, 2026
2 checks passed
@aserto-bot
aserto-bot deleted the slim-asertoerror-single-wrapped-error branch August 24, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants