github.com/triarius/goreleaser@v1.12.5/internal/pipe/pipe.go (about)

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