-
Notifications
You must be signed in to change notification settings - Fork 293
/
error.go
40 lines (33 loc) · 863 Bytes
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package starkit
import (
"github.com/pkg/errors"
"go.starlark.net/starlark"
)
// ErrStopExecution is a sentinel value to stop Starlark execution but will not be propagated back to callers.
//
// It is used by the custom exit() built-in to allow halting Tiltfile execution in a non-fatal manner.
var ErrStopExecution = errors.New("stop execution")
// Keep unwrapping errors until we find an error with a backtrace.
func UnpackBacktrace(err error) error {
var bestEvalError *starlark.EvalError
current := err
for {
evalErr, ok := current.(*starlark.EvalError)
if ok {
bestEvalError = evalErr
}
wrapper, ok := current.(wrapper)
if !ok {
break
}
current = wrapper.Unwrap()
}
if bestEvalError != nil {
return errors.New(bestEvalError.Backtrace())
}
return err
}
// go 1.13 error wrapper
type wrapper interface {
Unwrap() error
}