diff --git a/cmd/run.go b/cmd/run.go index 86486d03977..eea60bf8e40 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -55,6 +55,12 @@ import ( const ( typeJS = "js" typeArchive = "archive" + + thresholdHaveFailedErroCode = 99 + setupTimeoutErrorCode = 100 + teardownTimeoutErrorCode = 101 + genericTimeoutErrorCode = 102 + genericEngineErrorCode = 103 ) var ( @@ -379,13 +385,29 @@ a commandline interface for interacting with it.`, progress.Progress = prog fprintf(stdout, "%s\x1b[0K\r", progress.String()) case err := <-errC: - if err != nil { - log.WithError(err).Error("Engine error") - } else { + cancel() + if err == nil { log.Debug("Engine terminated cleanly") + break mainLoop + } + + switch e := errors.Cause(err).(type) { + case lib.TimeoutError: + switch string(e) { + case "setup": + log.WithError(err).Error("Setup timeout") + return ExitCode{errors.New("Setup timeout"), setupTimeoutErrorCode} + case "teardown": + log.WithError(err).Error("Teardown timeout") + return ExitCode{errors.New("Teardown timeout"), teardownTimeoutErrorCode} + default: + log.WithError(err).Error("Engine timeout") + return ExitCode{errors.New("Engine timeout"), genericTimeoutErrorCode} + } + default: + log.WithError(err).Error("Engine error") + return ExitCode{errors.New("Engine Error"), genericEngineErrorCode} } - cancel() - break mainLoop case sig := <-sigC: log.WithField("sig", sig).Debug("Exiting in response to signal") cancel() @@ -429,7 +451,7 @@ a commandline interface for interacting with it.`, } if engine.IsTainted() { - return ExitCode{errors.New("some thresholds have failed"), 99} + return ExitCode{errors.New("some thresholds have failed"), thresholdHaveFailedErroCode} } return nil }, diff --git a/lib/timeout_error.go b/lib/timeout_error.go index 64aa6e209e2..06d86bb05e1 100644 --- a/lib/timeout_error.go +++ b/lib/timeout_error.go @@ -6,11 +6,11 @@ type TimeoutError string // NewTimeoutError returns a new TimeoutError reporting that timeout has happened at the provieded // place func NewTimeoutError(place string) TimeoutError { - return TimeoutError("Timeout during " + place) + return TimeoutError(place) } func (t TimeoutError) String() string { - return (string)(t) + return "Timeout during " + (string)(t) } func (t TimeoutError) Error() string { diff --git a/release notes/upcoming.md b/release notes/upcoming.md index 48ad8728042..a5d550272f9 100644 --- a/release notes/upcoming.md +++ b/release notes/upcoming.md @@ -12,3 +12,4 @@ Description of feature. * JS: Consistently report setup/teardown timeouts as such and switch the error message to be more expressive (#890) +* JS: Correctly exit with non zero exit code when setup or teardown timeouts (#892)