Skip to content

feat: add request-scoped error presentation - #59

Closed
peterkc wants to merge 2 commits into
bir:masterfrom
peterkc:feature/error-presentation-policy
Closed

peterkc wants to merge 2 commits into
bir:masterfrom
peterkc:feature/error-presentation-policy

Conversation

@peterkc

@peterkc peterkc commented Sep 13, 2026 •

Copy link
Copy Markdown

Summary

  • Add an opt-in request-context policy to ErrorHandler. Applications can suppress new cause/stack log fields and replace a 400 message. Defaults, error classification and non-400 responses stay unchanged.
  • Add ComposeErrorPresentationPolicies for independent application rules. All rules run in order; suppression combines with OR and the first non-nil message wins, including an empty string. Message selection never skips later privacy rules.
  • The composer snapshots its policy list and returns independent results. Attaching a context policy still replaces the previous policy rather than adding to it.
ErrorHandler -> composed policy
                 +-- privacy rule
                 +-- message rule
                 +-- fallback rule
                 |
                 v
              merged result -> logging / response decisions

Verification

Passed locally with Go 1.26.6:

  • make fmt
  • make lint
  • make test (race tests)
  • go build -v ./...

Tests cover default behavior, error precedence, headers, ordered composition, nil/empty results, ownership and concurrent use. The split-rule regression proves that an early message rule cannot bypass later suppression. Bounded duplication analysis found no new production duplication.

Local CodeRabbit reviewed all three changed files against the PR base and reported no findings. CI success is not yet established.

Review notes

Suppression affects only this ErrorHandler invocation's new cause/stack fields. Earlier fields and other log events remain unchanged. A replacement 400 message omits detailed fields; this is not general log redaction. Child policies must remain safe for concurrent use.

Keep original error classification and default response behavior.
Allow request-scoped policies to omit cause/stack enrichment and replace
only resolved 400 messages.
@peterkc peterkc changed the title Add request-scoped error presentation feat: add request-scoped error presentation Sep 14, 2026
@peterkc
peterkc marked this pull request as ready for review September 14, 2026 00:02
@bir

bir commented Sep 15, 2026

Copy link
Copy Markdown
Owner

declined. We can review a model for redaction later.

@bir bir closed this Sep 15, 2026
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.

2 participants