| 
									
										
										
										
											2018-09-12 14:18:01 -03:00
										 |  |  | // Package pipe provides generic erros for pipes to use. | 
					
						
							|  |  |  | package pipe | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 11:15:03 -03:00
										 |  |  | import ( | 
					
						
							|  |  |  | 	"errors" | 
					
						
							|  |  |  | 	"strings" | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2020-08-16 11:29:56 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-12 14:18:01 -03:00
										 |  |  | // ErrSnapshotEnabled happens when goreleaser is running in snapshot mode. | 
					
						
							|  |  |  | // It usually means that publishing and maybe some validations were skipped. | 
					
						
							|  |  |  | var ErrSnapshotEnabled = Skip("disabled during snapshot mode") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ErrSkipPublishEnabled happens if --skip-publish is set. | 
					
						
							|  |  |  | // It means that the part of a Piper that publishes its artifacts was not run. | 
					
						
							|  |  |  | var ErrSkipPublishEnabled = Skip("publishing is disabled") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-25 00:45:59 -03:00
										 |  |  | // ErrSkipAnnounceEnabled happens if --skip-announce is set. | 
					
						
							|  |  |  | var ErrSkipAnnounceEnabled = Skip("announcing is disabled") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-12 14:18:01 -03:00
										 |  |  | // ErrSkipSignEnabled happens if --skip-sign is set. | 
					
						
							|  |  |  | // It means that the part of a Piper that signs some things was not run. | 
					
						
							|  |  |  | var ErrSkipSignEnabled = Skip("artifact signing is disabled") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ErrSkipValidateEnabled happens if --skip-validate is set. | 
					
						
							|  |  |  | // It means that the part of a Piper that validates some things was not run. | 
					
						
							|  |  |  | var ErrSkipValidateEnabled = Skip("validation is disabled") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-19 09:31:57 -03:00
										 |  |  | // ErrSkipDisabledPipe happens when a pipe is skipped because it is not configured. | 
					
						
							|  |  |  | var ErrSkipDisabledPipe = ErrSkip{ | 
					
						
							| 
									
										
										
										
											2021-04-25 14:20:49 -03:00
										 |  |  | 	reason:   "pipe not configured/disabled", | 
					
						
							| 
									
										
										
										
											2021-04-19 09:31:57 -03:00
										 |  |  | 	expected: true, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 00:48:10 -03:00
										 |  |  | // IsSkip returns true if the error is an ErrSkip. | 
					
						
							| 
									
										
										
										
											2018-09-12 14:18:01 -03:00
										 |  |  | func IsSkip(err error) bool { | 
					
						
							| 
									
										
										
										
											2020-11-10 11:15:03 -03:00
										 |  |  | 	return errors.As(err, &ErrSkip{}) | 
					
						
							| 
									
										
										
										
											2018-09-12 14:18:01 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-19 09:31:57 -03:00
										 |  |  | // IsExpectedSkip returns true if the given error is ErrSkip and if it is an | 
					
						
							|  |  |  | // expected skip. | 
					
						
							|  |  |  | func IsExpectedSkip(err error) bool { | 
					
						
							|  |  |  | 	skipErr := ErrSkip{} | 
					
						
							|  |  |  | 	if !errors.As(err, &skipErr) { | 
					
						
							|  |  |  | 		return false | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return skipErr.expected | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 00:48:10 -03:00
										 |  |  | // ErrSkip occurs when a pipe is skipped for some reason. | 
					
						
							| 
									
										
										
										
											2018-09-12 14:18:01 -03:00
										 |  |  | type ErrSkip struct { | 
					
						
							| 
									
										
										
										
											2021-04-19 09:31:57 -03:00
										 |  |  | 	reason   string | 
					
						
							|  |  |  | 	expected bool | 
					
						
							| 
									
										
										
										
											2018-09-12 14:18:01 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 00:48:10 -03:00
										 |  |  | // Error implements the error interface. returns the reason the pipe was skipped. | 
					
						
							| 
									
										
										
										
											2018-09-12 14:18:01 -03:00
										 |  |  | func (e ErrSkip) Error() string { | 
					
						
							|  |  |  | 	return e.reason | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 00:48:10 -03:00
										 |  |  | // Skip skips this pipe with the given reason. | 
					
						
							| 
									
										
										
										
											2018-09-12 14:18:01 -03:00
										 |  |  | func Skip(reason string) ErrSkip { | 
					
						
							|  |  |  | 	return ErrSkip{reason: reason} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-08-16 11:29:56 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | // SkipMemento remembers previous skip errors so you can return them all at once later. | 
					
						
							|  |  |  | type SkipMemento struct { | 
					
						
							|  |  |  | 	skips []string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Remember a skip. | 
					
						
							|  |  |  | func (e *SkipMemento) Remember(err error) { | 
					
						
							|  |  |  | 	for _, skip := range e.skips { | 
					
						
							|  |  |  | 		if skip == err.Error() { | 
					
						
							|  |  |  | 			return | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	e.skips = append(e.skips, err.Error()) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Evaluate return a skip error with all previous skips, or nil if none happened. | 
					
						
							|  |  |  | func (e *SkipMemento) Evaluate() error { | 
					
						
							|  |  |  | 	if len(e.skips) == 0 { | 
					
						
							|  |  |  | 		return nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return Skip(strings.Join(e.skips, ", ")) | 
					
						
							|  |  |  | } |