...

Source file src/github.com/goph/emperror/handler/bugsnaghandler/error.go

Documentation: github.com/goph/emperror/handler/bugsnaghandler

     1  package bugsnaghandler
     2  
     3  import (
     4  	berrors "github.com/bugsnag/bugsnag-go/errors"
     5  	"github.com/pkg/errors"
     6  )
     7  
     8  type stackTracer interface {
     9  	Error() string
    10  	StackTrace() errors.StackTrace
    11  }
    12  
    13  type errorWithStackFrames struct {
    14  	err stackTracer
    15  }
    16  
    17  // newErrorWithStackFrames returns a new error implementing the
    18  // github.com/bugsnag/bugsnag-go/errors.ErrorWithStackFrames interface.
    19  func newErrorWithStackFrames(err stackTracer) *errorWithStackFrames {
    20  	return &errorWithStackFrames{err}
    21  }
    22  
    23  // Error implements the error interface.
    24  func (e *errorWithStackFrames) Error() string {
    25  	return e.err.Error()
    26  }
    27  
    28  // Cause implements the github.com/pkg/errors.causer interface.
    29  func (e *errorWithStackFrames) Cause() error {
    30  	return e.err
    31  }
    32  
    33  // StackTrace implements the github.com/pkg/errors.stackTracer interface.
    34  func (e *errorWithStackFrames) StackTrace() errors.StackTrace {
    35  	return e.err.StackTrace()
    36  }
    37  
    38  func (e *errorWithStackFrames) StackFrames() []berrors.StackFrame {
    39  	stackTrace := e.err.StackTrace()
    40  	stackFrames := make([]berrors.StackFrame, len(stackTrace))
    41  
    42  	for i, frame := range stackTrace {
    43  		stackFrames[i] = berrors.NewStackFrame(uintptr(frame))
    44  	}
    45  
    46  	return stackFrames
    47  }
    48  

View as plain text