Skip to content

PROPOSAL: Allow hiding part of the stack trace #129

Open

Description

@decibel

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.

Activity

  1. davecheney commented on Aug 4, 2017

    @davecheney
    Member
  2. decibel commented on Feb 6, 2018

    @decibel
    Author

    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]
    }
    
  3. thebitguru commented on May 22, 2018

    @thebitguru

    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) :)

  4. davecheney commented on May 23, 2018

    @davecheney
    Member
  5. thebitguru commented on May 23, 2018

    @thebitguru

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

  6. segevfiner commented on Jun 26, 2019

    @segevfiner

    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.

  7. segevfiner commented on Jun 30, 2019

    @segevfiner

    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.

  8. segevfiner commented on Jun 30, 2019

    @segevfiner

    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.

  9. dingyaguang117 commented on Aug 23, 2021

    @dingyaguang117

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions