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

Commit 109ee59

Browse files
committed
simplify pc
1 parent 258d126 commit 109ee59

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

errors.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ func (l loc) Location() (string, int) {
2828

2929
// New returns an error that formats as the given text.
3030
func New(text string) error {
31+
pc, _, _, _ := runtime.Caller(1)
3132
return struct {
3233
error
3334
loc
3435
}{
3536
fmt.Errorf(text),
36-
loc(pc()),
37+
loc(pc),
3738
}
3839
}
3940

@@ -57,10 +58,11 @@ func Wrap(cause error, message string) error {
5758
if cause == nil {
5859
return nil
5960
}
61+
pc, _, _, _ := runtime.Caller(1)
6062
return &e{
6163
cause: cause,
6264
message: message,
63-
loc: loc(pc()),
65+
loc: loc(pc),
6466
}
6567
}
6668

@@ -132,8 +134,3 @@ func Fprint(w io.Writer, err error) {
132134
err = cause.Cause()
133135
}
134136
}
135-
136-
func pc() uintptr {
137-
pc, _, _, _ := runtime.Caller(2)
138-
return pc
139-
}

0 commit comments

Comments
 (0)