Fixed the same missing Err() issue in context.go#766
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a regression where Context.Err() could drop the main error field when ErrorStackMarshaler(err) returns nil, aligning context.go behavior with the earlier fix applied to event.go (PR #763).
Changes:
- Update
Context.Err()to not return early whenErrorStackMarshalerreturnsnil, soAnErrstill records the error field. - Update
TestContext_ErrWithNilStackMarshalerto assert the error field is still emitted when stack marshaling yieldsnil.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| context.go | Removes the early return on nil stack-marshaler output so the main error field is still logged. |
| context_test.go | Adjusts expectations/documentation to verify error logging is preserved even without a stack trace. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| case nil: | ||
| return c // do nothing with nil errors | ||
| // ErrorStackMarshaler returned nil — the error has no stack trace to | ||
| // attach. Fall through and still log the error via AnErr below. |
There was a problem hiding this comment.
The inline comment says “Fall through” inside a Go type-switch, but there is no fallthrough statement here. This wording can be misleading since “fallthrough” has a specific meaning in Go switches; consider rephrasing to something like “do nothing here; continue after the switch and still log the error via AnErr below.”
| // attach. Fall through and still log the error via AnErr below. | |
| // attach. Do nothing here; continue after the switch and still log | |
| // the error via AnErr below. |
There was a problem hiding this comment.
I copied the language from the other PR's change in event.go. Consistency rules (or I could change both in this PR, what say you @rs)?
Since #763 was merged instead of #758, only event.go was fixed. Need the same fix for context.go