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
{{ message }}
Repository navigation
PROPOSAL: Allow hiding part of the stack trace #129
Taking inspiration from how pkg/errors is meant as a drop-in replacement for the standard errors package, I have created an errors package that's specific to a larger project I'm involved in. That makes it easy to customize error behavior in the future. This package is mostly thin wrappers around pkg/errors.
The one downside to this is the stacks end up with an extra layer. Obviously I could fix that, but as far as I can tell it would require a fair amount of code duplication with pkg/errors.
I think there is a fairly easy way around this though; add an exposedStack *stack to withStack{}, and allow for callers to modify the boundaries of exposedStack. By default, exposedStack would be stack[:] so everything would work as today.
I think this would also make it easier for someone to satisfy #111, since they wouldn't need to duplicate any of the printing or other interfaces.
Reacted by Farhan Ahmad, Ali Koyuncu, Yaguang Ding and Kaarel Raspel
Thanks you for your proposal. I can see what you want to do, but not _how_
to do itm can you show some code to demonstrate what happens today, and
what could be changed to address that in the future.
Thanks
Dave
On Sat, 5 Aug 2017, 03:05 Jim Nasby ***@***.***> wrote:
Taking inspiration from how pkg/errors is meant as a drop-in replacement
for the standard errors package, I have created an errors package that's
specific to a larger project I'm involved in. That makes it easy to
customize error behavior in the future. This package is mostly thin
wrappers around pkg/errors.
The one downside to this is the stacks end up with an extra layer.
Obviously I could fix that, but as far as I can tell it would require a
fair amount of code duplication with pkg/errors.
I think there is a fairly easy way around this though; add an exposedStack
*stack to withStack{}, and allow for callers to modify the boundaries of
exposedStack. By default, exposedStack would be stack[:] so everything
would work as today.
I think this would also make it easier for someone to satisfy #111
<#111>, since they wouldn't need to
duplicate any of the printing or other interfaces.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#129>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAcA6MB-hhnwXb2TZRHAOnODjqf-FrHks5sU09TgaJpZM4Ot9ev>
.
I think there would need to be a func SetStackBounds(start,end int) that found the first error that had a stack trace and adjusted it's stack trace accordingly. For withStack{}, this might look like....
type withStack struct {
error
*stack
originalStack *stack
}
func (w *withStack) SetStackBounds(start,end int) {
*w.stack=*w.originalStack[start,end]
}
I am in a similar boat as @decibel and would love to see this addressed. Another implementation of this approach, https://github.com/go-errors/errors/blob/master/error.go#L93, has a parameter to accomplish saving only a subset of the stack. There are at least two other implementations of this need that I have seen and I am hoping that we can all standardize on a single one (ideally, this one) :)
To be clear, the reason this is not done is I do not know an algorithm for
gluing together two chains of program counters. This is the roadblock for
this issue.
A simple option is to add functions like WrapSkip(err error, message string, skip int) error and pass the skip value down to callers() and add it to the hard-coded 3. It seems the Go 2 errors proposal was reduced to only contain the point the error was created rather than a stack trace, so this package probably still has a place after it, and might even want to support its interfaces to integrate with it.
Activity
davecheney commentedon Aug 4, 2017
decibel commentedon Feb 6, 2018
I think there would need to be a
func SetStackBounds(start,end int)that found the first error that had a stack trace and adjusted it's stack trace accordingly. For withStack{}, this might look like....thebitguru commentedon May 22, 2018
I am in a similar boat as @decibel and would love to see this addressed. Another implementation of this approach, https://github.com/go-errors/errors/blob/master/error.go#L93, has a parameter to accomplish saving only a subset of the stack. There are at least two other implementations of this need that I have seen and I am hoping that we can all standardize on a single one (ideally, this one) :)
davecheney commentedon May 23, 2018
thebitguru commentedon May 23, 2018
That's helpful. Thanks for the response and more context, @davecheney.
segevfiner commentedon Jun 26, 2019
A simple option is to add functions like
WrapSkip(err error, message string, skip int) errorand pass theskipvalue down tocallers()and add it to the hard-coded3. It seems the Go 2 errors proposal was reduced to only contain the point the error was created rather than a stack trace, so this package probably still has a place after it, and might even want to support its interfaces to integrate with it.segevfiner commentedon Jun 30, 2019
Here's an untested implementation of this: https://github.com/segevfiner/pkg-errors/tree/stack-skip
An alternative is to have stuff like
WrapOptions(err error, message string, opts Options) errorso we can add other stuff in the future.Should this look acceptable I can send it in as a PR.
segevfiner commentedon Jun 30, 2019
Here's an untested implementation of this: https://github.com/segevfiner/pkg-errors/tree/stack-skip
An alternative is to have functions like
WrapOptions(err error, message string, opts Options) errorso we can add other stuff in the future.Should this look acceptable I can send it in as a PR.
dingyaguang117 commentedon Aug 23, 2021
Really need this, It's easy to implement some common error-processing operations.