github.com/goreleaser/goreleaser@v1.25.1/internal/pipe/pipe.go (about) 1 // Package pipe provides generic errors for pipes to use. 2 package pipe 3 4 import ( 5 "errors" 6 "fmt" 7 "strings" 8 ) 9 10 // ErrSnapshotEnabled happens when goreleaser is running in snapshot mode. 11 // It usually means that publishing and maybe some validations were skipped. 12 var ErrSnapshotEnabled = Skip("disabled during snapshot mode") 13 14 // ErrSkipPublishEnabled happens if --skip-publish is set. 15 // It means that the part of a Piper that publishes its artifacts was not run. 16 var ErrSkipPublishEnabled = Skip("publishing is disabled") 17 18 // ErrSkipAnnounceEnabled happens if --skip-announce is set. 19 var ErrSkipAnnounceEnabled = Skip("announcing is disabled") 20 21 // ErrSkipSignEnabled happens if --skip-sign is set. 22 // It means that the part of a Piper that signs some things was not run. 23 var ErrSkipSignEnabled = Skip("artifact signing is disabled") 24 25 // ErrSkipValidateEnabled happens if --skip-validate is set. 26 // It means that the part of a Piper that validates some things was not run. 27 var ErrSkipValidateEnabled = Skip("validation is disabled") 28 29 // IsSkip returns true if the error is an ErrSkip. 30 func IsSkip(err error) bool { 31 return errors.As(err, &ErrSkip{}) 32 } 33 34 // ErrSkip occurs when a pipe is skipped for some reason. 35 type ErrSkip struct { 36 reason string 37 } 38 39 // Error implements the error interface. returns the reason the pipe was skipped. 40 func (e ErrSkip) Error() string { 41 return e.reason 42 } 43 44 // Skip skips this pipe with the given reason. 45 func Skip(reason string) ErrSkip { 46 return ErrSkip{reason: reason} 47 } 48 49 // Skipf skips this pipe with the given reason. 50 func Skipf(format string, a ...any) ErrSkip { 51 return Skip(fmt.Sprintf(format, a...)) 52 } 53 54 // SkipMemento remembers previous skip errors so you can return them all at once later. 55 type SkipMemento struct { 56 skips []string 57 } 58 59 // Remember a skip. 60 func (e *SkipMemento) Remember(err error) { 61 for _, skip := range e.skips { 62 if skip == err.Error() { 63 return 64 } 65 } 66 e.skips = append(e.skips, err.Error()) 67 } 68 69 // Evaluate return a skip error with all previous skips, or nil if none happened. 70 func (e *SkipMemento) Evaluate() error { 71 if len(e.skips) == 0 { 72 return nil 73 } 74 return Skip(strings.Join(e.skips, ", ")) 75 }