-
Notifications
You must be signed in to change notification settings - Fork 290
/
build_errors.go
68 lines (53 loc) · 1.71 KB
/
build_errors.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package engine
import (
"context"
"fmt"
"github.com/pkg/errors"
"github.com/windmilleng/tilt/internal/logger"
)
// Nothing is on fire, this is an expected case like a container builder being
// passed a build with no attached container.
// `level` indicates at what log level this error should be shown to the user
type RedirectToNextBuilder struct {
error
level logger.Level
}
func WrapRedirectToNextBuilder(err error, level logger.Level) RedirectToNextBuilder {
return RedirectToNextBuilder{err, level}
}
func SilentRedirectToNextBuilderf(msg string, a ...interface{}) RedirectToNextBuilder {
// Only show to user in Debug mode
return RedirectToNextBuilder{fmt.Errorf(msg, a...), logger.DebugLvl}
}
func RedirectToNextBuilderInfof(msg string, a ...interface{}) RedirectToNextBuilder {
return RedirectToNextBuilder{fmt.Errorf(msg, a...), logger.InfoLvl}
}
var _ error = RedirectToNextBuilder{}
// Something is wrong enough that we shouldn't bother falling back to other
// BaD's -- they won't work.
type DontFallBackError struct {
error
}
func WrapDontFallBackError(err error) DontFallBackError {
return DontFallBackError{err}
}
func DontFallBackErrorf(msg string, a ...interface{}) DontFallBackError {
return DontFallBackError{fmt.Errorf(msg, a...)}
}
var _ error = DontFallBackError{}
// A permanent error indicates that the whole build pipeline needs to stop.
// It will never recover, even on subsequent rebuilds.
func isPermanentError(err error) bool {
cause := errors.Cause(err)
return cause == context.Canceled
}
func shouldFallBackForErr(err error) bool {
if isPermanentError(err) {
return false
}
cause := errors.Cause(err)
if _, ok := cause.(DontFallBackError); ok {
return false
}
return true
}