github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/engine/buildcontrol/build_errors.go (about) 1 package buildcontrol 2 3 import ( 4 "fmt" 5 6 "github.com/pkg/errors" 7 8 "github.com/tilt-dev/tilt/internal/store/buildcontrols" 9 "github.com/tilt-dev/tilt/pkg/logger" 10 ) 11 12 // Nothing is on fire, this is an expected case like a container builder being 13 // passed a build with no attached container. 14 // `level` indicates at what log level this error should be shown to the user 15 type RedirectToNextBuilder struct { 16 error 17 Level logger.Level 18 } 19 20 // UserFacing indicates whether this error should be messaged to the user by default. 21 // Should be `true` for messages we always want the user to read, e.g. "couldn't Live Update 22 // because we matched a fall_back_on file". 23 func (redir RedirectToNextBuilder) UserFacing() bool { 24 return redir.Level.AsSevereAs(logger.InfoLvl) 25 } 26 27 func WrapRedirectToNextBuilder(err error, level logger.Level) RedirectToNextBuilder { 28 return RedirectToNextBuilder{err, level} 29 } 30 31 func SilentRedirectToNextBuilderf(msg string, a ...interface{}) RedirectToNextBuilder { 32 // Only show to user in Debug mode 33 return RedirectToNextBuilder{fmt.Errorf(msg, a...), logger.DebugLvl} 34 } 35 36 func RedirectToNextBuilderInfof(msg string, a ...interface{}) RedirectToNextBuilder { 37 return RedirectToNextBuilder{fmt.Errorf(msg, a...), logger.InfoLvl} 38 } 39 40 var _ error = RedirectToNextBuilder{} 41 42 // Something is wrong enough that we shouldn't bother falling back to other 43 // BaD's -- they won't work. 44 type DontFallBackError struct { 45 error 46 } 47 48 func WrapDontFallBackError(err error) error { 49 if err == nil { 50 return nil 51 } 52 return DontFallBackError{err} 53 } 54 55 func DontFallBackErrorf(msg string, a ...interface{}) DontFallBackError { 56 return DontFallBackError{fmt.Errorf(msg, a...)} 57 } 58 59 func IsDontFallBackError(err error) bool { 60 _, ok := err.(DontFallBackError) 61 return ok 62 } 63 64 var _ error = DontFallBackError{} 65 66 func ShouldFallBackForErr(err error) bool { 67 if buildcontrols.IsFatalError(err) { 68 return false 69 } 70 71 cause := errors.Cause(err) 72 if IsDontFallBackError(cause) { 73 return false 74 } 75 return true 76 }