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.
diff --git a/errors.go b/errors.go
index ca5499e..d73f3d1 100644
--- a/errors.go
+++ b/errors.go
@@ -108,7 +108,16 @@
if err == nil {
return nil
}
- return wrap(err, message, callers())
+ return struct {
+ cause
+ *stack
+ }{
+ cause{
+ cause: err,
+ message: message,
+ },
+ callers(),
+ }
}
// Wrapf returns an error annotating err with the format specifier.
@@ -117,19 +126,15 @@
if err == nil {
return nil
}
- return wrap(err, fmt.Sprintf(format, args...), callers())
-}
-
-func wrap(err error, msg string, st *stack) error {
return struct {
cause
*stack
}{
cause{
cause: err,
- message: msg,
+ message: fmt.Sprintf(format, args...),
},
- st,
+ callers(),
}
}
@@ -213,8 +218,6 @@
return "unknown", 0
}
- file, line := fn.FileLine(pc)
-
// Here we want to get the source file path relative to the compile time
// GOPATH. As of Go 1.6.x there is no direct way to know the compiled
// GOPATH at runtime, but we can infer the number of path segments in the
@@ -239,6 +242,7 @@
// leading separator.
const sep = "/"
goal := strings.Count(fn.Name(), sep) + 2
+ file, line := fn.FileLine(pc)
i := len(file)
for n := 0; n < goal; n++ {
i = strings.LastIndex(file[:i], sep)
@@ -251,6 +255,5 @@
}
// get back to 0 or trim the leading separator
file = file[i+len(sep):]
-
return file, line
}