Browse Source

Add cause in Error.Error()

pull/1780/head
Jae Kwon 7 years ago
parent
commit
fb7bde9c24
4 changed files with 14 additions and 4 deletions
  1. +6
    -0
      CHANGELOG.md
  2. +5
    -1
      common/errors.go
  3. +2
    -2
      common/errors_test.go
  4. +1
    -1
      version/version.go

+ 6
- 0
CHANGELOG.md View File

@ -1,5 +1,11 @@
# Changelog
## 0.8.1 (develop branch)
FEATURES:
- [common] Error.Error() includes cause
## 0.8.0 (develop branch)
BREAKING:


+ 5
- 1
common/errors.go View File

@ -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?
}
}
}
}


+ 2
- 2
common/errors_test.go View File

@ -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")
}


+ 1
- 1
version/version.go View File

@ -1,3 +1,3 @@
package version
const Version = "0.8.0"
const Version = "0.8.1"

Loading…
Cancel
Save