Skip to content

Commit b28c3b0

Browse files
committed
Revert "Merge pull request #33 from meetme2meat/fix/make-package-compatabile-with-error-package"
This reverts commit 60174f7, reversing changes made to 5c4c70f.
1 parent b502428 commit b28c3b0

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

error.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type Error struct {
6868
// error then it will be used directly, if not, it will be passed to
6969
// fmt.Errorf("%v"). The stacktrace will point to the line of code that
7070
// called New.
71-
func New(e interface{}) error {
71+
func New(e interface{}) *Error {
7272
var err error
7373

7474
switch e := e.(type) {
@@ -90,7 +90,7 @@ func New(e interface{}) error {
9090
// error then it will be used directly, if not, it will be passed to
9191
// fmt.Errorf("%v"). The skip parameter indicates how far up the stack
9292
// to start the stacktrace. 0 is from the current call, 1 from its caller, etc.
93-
func Wrap(e interface{}, skip int) error {
93+
func Wrap(e interface{}, skip int) *Error {
9494
if e == nil {
9595
return nil
9696
}
@@ -120,12 +120,12 @@ func Wrap(e interface{}, skip int) error {
120120
// error message when calling Error(). The skip parameter indicates how far
121121
// up the stack to start the stacktrace. 0 is from the current call,
122122
// 1 from its caller, etc.
123-
func WrapPrefix(e interface{}, prefix string, skip int) error {
123+
func WrapPrefix(e interface{}, prefix string, skip int) *Error {
124124
if e == nil {
125125
return nil
126126
}
127127

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

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

error_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func BenchmarkStackFormat(b *testing.B) {
2222
}
2323

2424
e := Errorf("hi")
25-
_ = string(e.(*Error).Stack())
25+
_ = string(e.Stack())
2626
}()
2727

2828
a()
@@ -63,14 +63,14 @@ func TestStackFormat(t *testing.T) {
6363

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

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

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

73-
stack := string(e.(*Error).Stack())
73+
stack := string(e.Stack())
7474

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

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

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

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

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

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

193-
prefixed := WrapPrefix(e, "prefix", 0).(*Error)
193+
prefixed := WrapPrefix(e, "prefix", 0)
194194
original := e.(*Error)
195195

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

0 commit comments

Comments
 (0)