Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit 431554f

Browse files
committed
Remove errors.wrap helper
`errors.wrap` existed to avoid the conflict between the type, `errors.cause` and the formal parameter `cause`. The parameter was renamed to err in #32 so there is no need for the helper.
1 parent 936b5d7 commit 431554f

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

errors.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,16 @@ func Wrap(err error, message string) error {
108108
if err == nil {
109109
return nil
110110
}
111-
return wrap(err, message, callers())
111+
return struct {
112+
cause
113+
*stack
114+
}{
115+
cause{
116+
cause: err,
117+
message: message,
118+
},
119+
callers(),
120+
}
112121
}
113122

114123
// Wrapf returns an error annotating err with the format specifier.
@@ -117,19 +126,15 @@ func Wrapf(err error, format string, args ...interface{}) error {
117126
if err == nil {
118127
return nil
119128
}
120-
return wrap(err, fmt.Sprintf(format, args...), callers())
121-
}
122-
123-
func wrap(err error, msg string, st *stack) error {
124129
return struct {
125130
cause
126131
*stack
127132
}{
128133
cause{
129134
cause: err,
130-
message: msg,
135+
message: fmt.Sprintf(format, args...),
131136
},
132-
st,
137+
callers(),
133138
}
134139
}
135140

@@ -213,8 +218,6 @@ func location(pc uintptr) (string, int) {
213218
return "unknown", 0
214219
}
215220

216-
file, line := fn.FileLine(pc)
217-
218221
// Here we want to get the source file path relative to the compile time
219222
// GOPATH. As of Go 1.6.x there is no direct way to know the compiled
220223
// GOPATH at runtime, but we can infer the number of path segments in the
@@ -239,6 +242,7 @@ func location(pc uintptr) (string, int) {
239242
// leading separator.
240243
const sep = "/"
241244
goal := strings.Count(fn.Name(), sep) + 2
245+
file, line := fn.FileLine(pc)
242246
i := len(file)
243247
for n := 0; n < goal; n++ {
244248
i = strings.LastIndex(file[:i], sep)
@@ -251,6 +255,5 @@ func location(pc uintptr) (string, int) {
251255
}
252256
// get back to 0 or trim the leading separator
253257
file = file[i+len(sep):]
254-
255258
return file, line
256259
}

0 commit comments

Comments
 (0)