Skip to content

Commit

Permalink
Exit with non zero code when setup/teardown timeouts fix #868
Browse files Browse the repository at this point in the history
There are now 4 new non zero exit codes that will be revisioned at later
date when we more exit codes arise.

The 4 new ones are for each of setup and teardown timeouts, if it is a
timeout in the engine but it is not in setup/teardown - no such is known
at this time and 1 for engine error which is not timeout.
  • Loading branch information
mstoykov committed Jan 7, 2019
1 parent 7266aed commit aa35ca8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
31 changes: 26 additions & 5 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ import (
const (
typeJS = "js"
typeArchive = "archive"

setupTimeoutErrorCode = 100
teardownTimeoutErrorCode = 101
genericTimeoutErrorCode = 102
genericEngineErrorCode = 103
)

var (
Expand Down Expand Up @@ -379,13 +384,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()
Expand Down
4 changes: 2 additions & 2 deletions lib/timeout_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit aa35ca8

Please sign in to comment.