You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a common pattern in domain logic, where the creation of errors has been standardised with helper functions.
For example in a http handler one might want to easily create a validation error, with a custom errorCode, without having to type the complete stacktrace boilerplate.
iferr:=domain.DoTheThing(ctx, args); err!=nil {
// call to stacktrace.Propagate has been deferred to an opaque package// containing all of the domain semantic conventionsreturnnil, errors.InvalidThingDone(err, args)
}
// stacktrace will always point to its caller, which is in this case the helper function
The problem is that stacktrace will use the helper function callsite instead of the line of invocation of said helper function.
It would not be a problem if go allowed explicit inlining, but that does not seem possible currently.
The idea would be to add an optional parameter in order to skip n runtime call frames, allowing forward declaration of error helpers, without impacting the stacktrace.
Is it something that could benefit this library (as a new public function), or is it something totally out of scope for the community ?
// example implementation of the `errors` package with proposed functionnalities// API is given as an example// builder created at runtimevarinvalidThingDoneErr=stacktrace.NewErrorBuilder()
// invokes the error builder which skips this frame, being the actual helper call sitefuncInvalidThingDone(errerror, argsany) error {
returninvalidThingDoneErr.
WithCode(0xdeadbeef).
Propagate(err)
}
The text was updated successfully, but these errors were encountered:
There is a common pattern in domain logic, where the creation of errors has been standardised with helper functions.
For example in a http handler one might want to easily create a validation error, with a custom errorCode, without having to type the complete
stacktrace
boilerplate.The problem is that
stacktrace
will use the helper function callsite instead of the line of invocation of said helper function.It would not be a problem if go allowed explicit inlining, but that does not seem possible currently.
The idea would be to add an optional parameter in order to skip
n
runtime call frames, allowing forward declaration of error helpers, without impacting the stacktrace.Is it something that could benefit this library (as a new public function), or is it something totally out of scope for the community ?
The text was updated successfully, but these errors were encountered: