-
Notifications
You must be signed in to change notification settings - Fork 51
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
feat: Add WithStack to the errors package #870
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #870 +/- ##
===========================================
+ Coverage 59.81% 59.82% +0.01%
===========================================
Files 157 157
Lines 17401 17403 +2
===========================================
+ Hits 10408 10412 +4
+ Misses 6056 6055 -1
+ Partials 937 936 -1
|
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.
Is a nice addition/feat, thanks
func WithStack(err error) error { | ||
return withStackTrace(err.Error()) | ||
} | ||
|
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.
I guess we could have keyvals here as well.
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.
func WithKeyVals(...)
?
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.
no I mean
func WithStack(err error, keyvals ...KV) error {
return withStackTrace(err.Error(), keyvals...)
}
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.
just to be consistent with the other functions
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.
This way if you want to append keyVals you have to also add a stackTrace - if you add func WithKeyVals(...)
, you get both options (keyvals noStacktrace, keyvals with stacttrace). Follows the builder pattern and scales better if we end up adding more options. The only other funcs I could see were constructors, which IMO are different to these funcs and thus have no need for extra 'consistency' params.
Cost is super minimal though, and I guess you could add func WithKeyVals(keyvals ...KV)
anyway
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.
Stacktrace are always added. WithKeyvals(...)
would have to be a method on the defra error type which would only work it the error passed to the function is a defra error. Not sure there is any advantage to doing that.
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.
Ah true, as you'd be then going through the hassle of amending an external error, yet leaving it in an inconsistent state to defra errors. Cheers!
Benchmark ResultsSummary
✅ See Better Results...
❌ See Worse Results...
✨ See Unchanged Results...
🐋 See Full Results...
|
idea: use build tag to test this file without |
It can still be tested with |
IMO testing with race is super important here - would be really bad to add a race condition in here. I think this was discussed in the original PR that added the errors package, one option was to break out extra tests to a separate file that doesnt run with |
Benchmark ResultsSummary
✅ See Better Results...
❌ See Worse Results...
✨ See Unchanged Results...
🐋 See Full Results...
|
655d6d3
to
47ec3e7
Compare
Benchmark ResultsSummary
✅ See Better Results...
❌ See Worse Results...
✨ See Unchanged Results...
🐋 See Full Results...
|
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.
LGTM
Relevant issue(s) Resolves sourcenetwork#869 Description This PR adds a WithStack function to the errors package to be able to add a stacktrace to a returned error without adding a message. It also fixes the TestErrorIs unit test.
Relevant issue(s)
Resolves #869
Description
This PR adds a
WithStack
function to the errors package to be able to add a stacktrace to a returned error without adding a message. It also fixes theTestErrorIs
unit test.How has this been tested?
Unit test
Specify the platform(s) on which this was tested: