Skip to content

Commit

Permalink
Merge pull request #66 from mailgun/thrawn/develop
Browse files Browse the repository at this point in the history
Added NewWithDepth() WrapWithDepth()
  • Loading branch information
thrawn01 authored May 5, 2020
2 parents 51a651a + d2e8955 commit d481c71
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion errors/context_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"io"

"github.com/mailgun/holster/stack"
"github.com/mailgun/holster/v3/stack"
pkg "github.com/pkg/errors"
)

Expand Down
29 changes: 28 additions & 1 deletion errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,21 @@ import (
"fmt"
"io"

"github.com/mailgun/holster/stack"
"github.com/mailgun/holster/v3/stack"
pkg "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

// New returns an error with the supplied message.
// New also records the stack trace at the depth specified.
func NewWithDepth(message string, depth int) error {
return &fundamental{
msg: message,
Stack: stack.New(depth),
}
}


// New returns an error with the supplied message.
// New also records the stack trace at the point it was called.
func New(message string) error {
Expand Down Expand Up @@ -184,6 +194,23 @@ func (w *withStack) Format(s fmt.State, verb rune) {
}
}

// WrapStack returns an error annotating err with a stack trace
// at the depth indicated. A calling depth of 1 is the function that
// called WrapStack. If err is nil, Wrap returns nil.
func WrapWithDepth(err error, message string, depth int) error {
if err == nil {
return nil
}
err = &withMessage{
cause: err,
msg: message,
}
return &withStack{
err,
stack.New(depth),
}
}

// Wrap returns an error annotating err with a stack trace
// at the point Wrap is called, and the supplied message.
// If err is nil, Wrap returns nil.
Expand Down
2 changes: 1 addition & 1 deletion errors/with_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package errors
import (
"fmt"

"github.com/mailgun/holster/stack"
"github.com/mailgun/holster/v3/stack"
)

// Implement this interface to pass along unstructured context to the logger
Expand Down
6 changes: 3 additions & 3 deletions errors/with_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"strings"
"testing"

"github.com/mailgun/holster/errors"
"github.com/mailgun/holster/stack"
. "gopkg.in/check.v1"
"github.com/ahmetb/go-linq"
"github.com/mailgun/holster/v3/errors"
"github.com/mailgun/holster/v3/stack"
. "gopkg.in/check.v1"
)

type TestError struct {
Expand Down

0 comments on commit d481c71

Please sign in to comment.