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