@@ -17,21 +17,27 @@ func RegisterHelper(helper Helper) {
1717
1818// New creates an error with the provided text and automatically wraps it with line information.
1919func New (s string ) Chain {
20- return wrap (errors .New (s ), "" )
20+ return wrap (errors .New (s ), "" , 0 )
2121}
2222
2323// Wrap encapsulates the error, stores a contextual prefix and automatically obtains
2424// a stack trace.
2525func Wrap (err error , prefix string ) Chain {
26- return wrap (err , prefix )
26+ return wrap (err , prefix , 0 )
2727}
2828
29- func wrap (err error , prefix string ) (c Chain ) {
29+ // WrapSkipFrames is a special version of Wrap that skips extra n frames when determining error location.
30+ // Normally only used when wrapping the library
31+ func WrapSkipFrames (err error , prefix string , n uint ) Chain {
32+ return wrap (err , prefix , int (n ))
33+ }
34+
35+ func wrap (err error , prefix string , skipFrames int ) (c Chain ) {
3036 var ok bool
3137 if c , ok = err .(Chain ); ok {
32- c = append (c , newLink (err , prefix ))
38+ c = append (c , newLink (err , prefix , skipFrames ))
3339 } else {
34- c = Chain {newLink (err , prefix )}
40+ c = Chain {newLink (err , prefix , skipFrames )}
3541 }
3642 for _ , h := range helpers {
3743 if ! h (c , err ) {
0 commit comments