From e9688813e4ffad908f2e8a3218d852dc293d8529 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sun, 24 Jul 2016 12:09:05 -0400 Subject: [PATCH] Refine error handling behavior so that exit 1 happens as long as error is non-nil --- CHANGELOG.md | 1 + errors.go | 2 +- errors_test.go | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4976635..26dd564 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## [Unreleased] ### Added - Flag type code generation via `go generate` +- Write to stderr and exit 1 if action returns non-nil error ### Changed - Raise minimum tested/supported Go version to 1.2+ diff --git a/errors.go b/errors.go index 15ac790..c7d8c2f 100644 --- a/errors.go +++ b/errors.go @@ -93,6 +93,6 @@ func HandleExitCoder(err error) { if err.Error() != "" { fmt.Fprintln(ErrWriter, err) - OsExiter(1) } + OsExiter(1) } diff --git a/errors_test.go b/errors_test.go index e357dc4..04df031 100644 --- a/errors_test.go +++ b/errors_test.go @@ -100,7 +100,7 @@ func TestHandleExitCoder_ErrorWithoutMessage(t *testing.T) { err := errors.New("") HandleExitCoder(err) - expect(t, exitCode, 0) - expect(t, called, false) + expect(t, exitCode, 1) + expect(t, called, true) expect(t, ErrWriter.(*bytes.Buffer).String(), "") }