From fb7bde9c24b3c9d7c5e9926606760cb36ada3e8b Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Wed, 4 Apr 2018 13:43:19 -0700 Subject: [PATCH] Add cause in Error.Error() --- CHANGELOG.md | 6 ++++++ common/errors.go | 6 +++++- common/errors_test.go | 4 ++-- version/version.go | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f372d028..0da5ee204 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.8.1 (develop branch) + +FEATURES: + + - [common] Error.Error() includes cause + ## 0.8.0 (develop branch) BREAKING: diff --git a/common/errors.go b/common/errors.go index c5efae9cf..1ee1fb349 100644 --- a/common/errors.go +++ b/common/errors.go @@ -200,7 +200,11 @@ func (err *cmnError) Format(s fmt.State, verb rune) { s.Write([]byte("--= /Error =--\n")) } else { // Write msg. - s.Write([]byte(fmt.Sprintf("Error{`%v`}", err.msg))) // TODO tick-esc? + if err.cause != nil { + s.Write([]byte(fmt.Sprintf("Error{`%s` (cause: %v)}", err.msg, err.cause))) // TODO tick-esc? + } else { + s.Write([]byte(fmt.Sprintf("Error{`%s`}", err.msg))) // TODO tick-esc? + } } } } diff --git a/common/errors_test.go b/common/errors_test.go index 56f366179..2c5234f9f 100644 --- a/common/errors_test.go +++ b/common/errors_test.go @@ -28,7 +28,7 @@ func TestErrorPanic(t *testing.T) { assert.Equal(t, pnk{"something"}, err.Cause()) assert.Equal(t, pnk{"something"}, err.T()) assert.Equal(t, "This is the message in ErrorWrap(r, message).", err.Message()) - assert.Equal(t, "Error{`This is the message in ErrorWrap(r, message).`}", fmt.Sprintf("%v", err)) + assert.Equal(t, "Error{`This is the message in ErrorWrap(r, message).` (cause: {something})}", fmt.Sprintf("%v", err)) assert.Contains(t, fmt.Sprintf("%#v", err), "Message: This is the message in ErrorWrap(r, message).") assert.Contains(t, fmt.Sprintf("%#v", err), "Stack Trace:\n 0") } @@ -40,7 +40,7 @@ func TestErrorWrapSomething(t *testing.T) { assert.Equal(t, "something", err.Cause()) assert.Equal(t, "something", err.T()) assert.Equal(t, "formatter01", err.Message()) - assert.Equal(t, "Error{`formatter01`}", fmt.Sprintf("%v", err)) + assert.Equal(t, "Error{`formatter01` (cause: something)}", fmt.Sprintf("%v", err)) assert.Regexp(t, `Message: formatter01\n`, fmt.Sprintf("%#v", err)) assert.Contains(t, fmt.Sprintf("%#v", err), "Stack Trace:\n 0") } diff --git a/version/version.go b/version/version.go index f17ed2ed3..b389a63a0 100644 --- a/version/version.go +++ b/version/version.go @@ -1,3 +1,3 @@ package version -const Version = "0.8.0" +const Version = "0.8.1"