Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

PROPOSAL: Allow hiding part of the stack trace #129

Open
decibel opened this issue Aug 4, 2017 · 9 comments
Open

PROPOSAL: Allow hiding part of the stack trace #129

decibel opened this issue Aug 4, 2017 · 9 comments

Comments

@decibel
Copy link

decibel commented Aug 4, 2017

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.

@davecheney
Copy link
Member

davecheney commented Aug 4, 2017 via email

@decibel
Copy link
Author

decibel commented 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....

type withStack struct {
    error
    *stack
    originalStack *stack
}

func (w *withStack) SetStackBounds(start,end int) {
    *w.stack=*w.originalStack[start,end]
}

@thebitguru
Copy link

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
Copy link
Member

davecheney commented May 23, 2018 via email

@thebitguru
Copy link

That's helpful. Thanks for the response and more context, @davecheney.

@segevfiner
Copy link

segevfiner commented Jun 26, 2019

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.

@segevfiner
Copy link

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) error so we can add other stuff in the future.

Should this look acceptable I can send it in as a PR.

@segevfiner
Copy link

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) error so we can add other stuff in the future.

Should this look acceptable I can send it in as a PR.

@dingyaguang117
Copy link

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) error so we can add other stuff in the future.

Should this look acceptable I can send it in as a PR.

Really need this, It's easy to implement some common error-processing operations.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants