-
-
Notifications
You must be signed in to change notification settings - Fork 35
feat(code): allow any code type #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Change Code(...) to accept any and Code() to return any. Update docs/tests for int and string codes. Fix stacktrace path normalization in module mode. BREAKING CHANGE: OopsError.Code() now returns any (was string).
samber
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contrib.
Just 1 comment
| return e.code | ||
| }, | ||
| ) | ||
| func (o OopsError) Code() any { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the recursive getDeepestErrorAttribute function ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
I initially avoided getDeepestErrorAttribute because it’s constrained to T comparable, and any isn’t comparable in general (e.g. map/slice). Also its coalescing logic assumes “zero value = empty”, which would incorrectly treat 0 as empty for int codes.
So I implemented a small custom recursion with an explicit emptiness rule: only nil and "" are considered “unset”, everything else (including 0) is a valid code.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #94 +/- ##
==========================================
+ Coverage 85.09% 85.57% +0.48%
==========================================
Files 13 13
Lines 939 943 +4
==========================================
+ Hits 799 807 +8
+ Misses 115 112 -3
+ Partials 25 24 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Good point. Let's merge! |
This PR addresses #33 by allowing oops.Code(...) to accept multiple code types (e.g. int and string) instead of only string.
Changes:
Note (Breaking Change):
value.