Skip to content

Commit

Permalink
Revert "Merge pull request #33 from meetme2meat/fix/make-package-comp…
Browse files Browse the repository at this point in the history
…atabile-with-error-package"

This reverts commit 60174f7, reversing
changes made to 5c4c70f.
  • Loading branch information
ConradIrwin committed May 14, 2021
1 parent b502428 commit b28c3b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type Error struct {
// error then it will be used directly, if not, it will be passed to
// fmt.Errorf("%v"). The stacktrace will point to the line of code that
// called New.
func New(e interface{}) error {
func New(e interface{}) *Error {
var err error

switch e := e.(type) {
Expand All @@ -90,7 +90,7 @@ func New(e interface{}) error {
// error then it will be used directly, if not, it will be passed to
// fmt.Errorf("%v"). The skip parameter indicates how far up the stack
// to start the stacktrace. 0 is from the current call, 1 from its caller, etc.
func Wrap(e interface{}, skip int) error {
func Wrap(e interface{}, skip int) *Error {
if e == nil {
return nil
}
Expand Down Expand Up @@ -120,12 +120,12 @@ func Wrap(e interface{}, skip int) error {
// error message when calling Error(). The skip parameter indicates how far
// up the stack to start the stacktrace. 0 is from the current call,
// 1 from its caller, etc.
func WrapPrefix(e interface{}, prefix string, skip int) error {
func WrapPrefix(e interface{}, prefix string, skip int) *Error {
if e == nil {
return nil
}

err, _ := Wrap(e, 1+skip).(*Error)
err := Wrap(e, 1+skip)

if err.prefix != "" {
prefix = fmt.Sprintf("%s: %s", prefix, err.prefix)
Expand All @@ -142,7 +142,7 @@ func WrapPrefix(e interface{}, prefix string, skip int) error {
// Errorf creates a new error with the given message. You can use it
// as a drop-in replacement for fmt.Errorf() to provide descriptive
// errors in return values.
func Errorf(format string, a ...interface{}) error {
func Errorf(format string, a ...interface{}) *Error {
return Wrap(fmt.Errorf(format, a...), 1)
}

Expand Down
14 changes: 7 additions & 7 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func BenchmarkStackFormat(b *testing.B) {
}

e := Errorf("hi")
_ = string(e.(*Error).Stack())
_ = string(e.Stack())
}()

a()
Expand Down Expand Up @@ -63,14 +63,14 @@ func TestStackFormat(t *testing.T) {

e, expected := Errorf("hi"), callers()

bs := [][]uintptr{e.(*Error).stack, expected}
bs := [][]uintptr{e.stack, expected}

if err := compareStacks(bs[0], bs[1]); err != nil {
t.Errorf("Stack didn't match")
t.Errorf(err.Error())
}

stack := string(e.(*Error).Stack())
stack := string(e.Stack())

if !strings.Contains(stack, "a: b(5)") {
t.Errorf("Stack trace does not contain source line: 'a: b(5)'")
Expand All @@ -93,7 +93,7 @@ func TestSkipWorks(t *testing.T) {
t.Fatal(err)
}

bs := [][]uintptr{Wrap("hi", 2).(*Error).stack, callersSkip(2)}
bs := [][]uintptr{Wrap("hi", 2).stack, callersSkip(2)}

if err := compareStacks(bs[0], bs[1]); err != nil {
t.Errorf("Stack didn't match")
Expand All @@ -118,14 +118,14 @@ func TestNew(t *testing.T) {
t.Errorf("Wrong message")
}

bs := [][]uintptr{New("foo").(*Error).stack, callers()}
bs := [][]uintptr{New("foo").stack, callers()}

if err := compareStacks(bs[0], bs[1]); err != nil {
t.Errorf("Stack didn't match")
t.Errorf(err.Error())
}

if err.(*Error).ErrorStack() != err.(*Error).TypeName()+" "+err.Error()+"\n"+string(err.(*Error).Stack()) {
if err.ErrorStack() != err.TypeName()+" "+err.Error()+"\n"+string(err.Stack()) {
t.Errorf("ErrorStack is in the wrong format")
}
}
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestWrapPrefixError(t *testing.T) {
t.Errorf("Constructor with an error failed")
}

prefixed := WrapPrefix(e, "prefix", 0).(*Error)
prefixed := WrapPrefix(e, "prefix", 0)
original := e.(*Error)

if prefixed.Err != original.Err || !reflect.DeepEqual(prefixed.stack, original.stack) || !reflect.DeepEqual(prefixed.frames, original.frames) || prefixed.Error() != "prefix: prefix: hi" {
Expand Down

0 comments on commit b28c3b0

Please sign in to comment.