Skip to content

Commit 5db6745

Browse files
committed
Merge branch 'exit-messages-and-codes'
2 parents 7b2f292 + 4f68c8e commit 5db6745

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

cli/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
type ExitCode byte
88

99
const (
10+
EXIT_SUCCESS = ExitCode(0)
1011
EXIT_BADARGS = ExitCode(1)
1112
EXIT_UNKNOWNPANIC = ExitCode(2) // same code as golang uses when the process dies naturally on an unhandled panic.
1213
EXIT_USER = ExitCode(3) // grab bag for general user input errors (try to make a more specific code if possible/useful)

cli/run_command.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"fmt"
45
"io"
56

67
"github.com/codegangsta/cli"
@@ -50,7 +51,10 @@ func RunCommandPattern(output io.Writer) cli.Command {
5051
result := RunFormula(scheduler, executor, formula, ctx.App.Writer)
5152
// Exit if the job failed collosally (if it just had a nonzero exit code, that's acceptable).
5253
if result.Error != nil {
53-
panic(Error.NewWith("job execution errored", SetExitCode(EXIT_USER)))
54+
panic(Exit.NewWith(
55+
fmt.Sprintf("job execution errored: %s", result.Error.Message()),
56+
SetExitCode(EXIT_USER), // TODO review exit code
57+
))
5458
}
5559

5660
// Output.

cli/twerk_command.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,18 @@ func TwerkCommandPattern(stdin io.Reader, stdout, stderr io.Writer) cli.Command
4545
go io.Copy(stderr, job.Outputs().Reader(2))
4646
result := job.Wait()
4747
if result.Error != nil {
48-
fmt.Fprintf(ctx.App.Writer, "error: %s\n", result.Error)
49-
} else {
50-
fmt.Fprintf(ctx.App.Writer, "done; exit code %d\n", result.ExitCode)
48+
panic(Exit.NewWith(
49+
fmt.Sprintf("job execution errored: %s", result.Error.Message()),
50+
SetExitCode(EXIT_USER), // TODO review exit code
51+
))
5152
}
53+
if result.ExitCode != 0 {
54+
panic(Exit.NewWith(
55+
fmt.Sprintf("done; action finished with exit status %d", result.ExitCode),
56+
SetExitCode(EXIT_JOB),
57+
))
58+
}
59+
panic(Exit.NewWith("done; action reported successful exit status", SetExitCode(EXIT_SUCCESS)))
5260
},
5361
}
5462
}

0 commit comments

Comments
 (0)