Skip to content

feat(context): unwrap joined errors in Context.Error() - #4729

Open
Vierblatt wants to merge 2 commits into
gin-gonic:masterfrom
Vierblatt:feat/unwrap-joined-errors
Open

feat(context): unwrap joined errors in Context.Error()#4729
Vierblatt wants to merge 2 commits into
gin-gonic:masterfrom
Vierblatt:feat/unwrap-joined-errors

Conversation

@Vierblatt

Copy link
Copy Markdown

Summary

  • Context.Error() now detects errors implementing Unwrap() []error (like those from errors.Join) and stores each unwrapped error as an individual entry in c.Errors
  • Preserves *gin.Error type metadata when a joined error contains one
  • Falls through to the normal single-error path when Unwrap() returns an empty slice

Motivation

Fixes #4237. When errors.Join(e1, e2) is passed to c.Error(), the joined error was stored as a single entry. This produced confusing output in errorMsgs.String() where the joined error's own \n-separated format mixed with Gin's numbered format:

Error #01 gin error
Error #02 service error
store error          <--- part of a joined error, not numbered
Error #03 other error

Now each joined error becomes its own numbered entry.

Test plan

  • Basic errors.Join(err1, err2) unwraps into two entries
  • Nested errors.Join recursively unwraps
  • *gin.Error type preserved inside a join
  • Empty Unwrap() []error degrades to single wrapped entry
  • All existing tests pass
  • Race detector clean

Vierblatt added 2 commits July 5, 2026 02:08
errors.Join() produces a single error implementing Unwrap() []error.
Previously, c.Error(errors.Join(e1, e2)) stored the joined error as one
entry, confusing errorMsgs output. Now each unwrapped error becomes an
individual entry, with gin.Error type preserved when applicable.

Fixes gin-gonic#4237
@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.33%. Comparing base (3dc1cd6) to head (5228977).
⚠️ Report is 292 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4729      +/-   ##
==========================================
- Coverage   99.21%   98.33%   -0.89%     
==========================================
  Files          42       48       +6     
  Lines        3182     3178       -4     
==========================================
- Hits         3157     3125      -32     
- Misses         17       43      +26     
- Partials        8       10       +2     
Flag Coverage Δ
?
--ldflags="-checklinkname=0" -tags sonic 98.31% <100.00%> (?)
-tags go_json 98.25% <100.00%> (?)
-tags nomsgpack 98.30% <100.00%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.25 98.33% <100.00%> (?)
go-1.26 98.33% <100.00%> (?)
macos-latest 98.33% <100.00%> (-0.89%) ⬇️
ubuntu-latest 98.33% <100.00%> (-0.89%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Unwrap joinErr in gin.Error()

1 participant