mirror of
https://github.com/pkg/errors.git
synced 2025-05-04 06:30:25 +00:00
simplify pc
This commit is contained in:
parent
258d1265c4
commit
109ee590a8
11
errors.go
11
errors.go
@ -28,12 +28,13 @@ func (l loc) Location() (string, int) {
|
||||
|
||||
// New returns an error that formats as the given text.
|
||||
func New(text string) error {
|
||||
pc, _, _, _ := runtime.Caller(1)
|
||||
return struct {
|
||||
error
|
||||
loc
|
||||
}{
|
||||
fmt.Errorf(text),
|
||||
loc(pc()),
|
||||
loc(pc),
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,10 +58,11 @@ func Wrap(cause error, message string) error {
|
||||
if cause == nil {
|
||||
return nil
|
||||
}
|
||||
pc, _, _, _ := runtime.Caller(1)
|
||||
return &e{
|
||||
cause: cause,
|
||||
message: message,
|
||||
loc: loc(pc()),
|
||||
loc: loc(pc),
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,8 +134,3 @@ func Fprint(w io.Writer, err error) {
|
||||
err = cause.Cause()
|
||||
}
|
||||
}
|
||||
|
||||
func pc() uintptr {
|
||||
pc, _, _, _ := runtime.Caller(2)
|
||||
return pc
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user