Skip to content

Commit

Permalink
Merge pull request #19 from morikuni/debug-string
Browse files Browse the repository at this point in the history
Change Debug’s value type to string
  • Loading branch information
morikuni committed Jan 21, 2019
2 parents b670d36 + 01e0a4c commit edf4ef2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions failure_test.go
Expand Up @@ -17,7 +17,7 @@ const (
)

func TestFailure(t *testing.T) {
base := failure.New(TestCodeA, failure.Message("xxx"), failure.Debug{"zzz": true})
base := failure.New(TestCodeA, failure.Message("xxx"), failure.Debug{"zzz": "true"})
pkgErr := errors.New("yyy")
tests := map[string]struct {
err error
Expand All @@ -30,12 +30,12 @@ func TestFailure(t *testing.T) {
wantError string
}{
"new": {
err: failure.New(TestCodeA, failure.Debug{"aaa": 1}),
err: failure.New(TestCodeA, failure.Debug{"aaa": "1"}),

shouldNil: false,
wantCode: TestCodeA,
wantMessage: "",
wantDebugs: []failure.Debug{{"aaa": 1}},
wantDebugs: []failure.Debug{{"aaa": "1"}},
wantStackLine: 33,
wantError: "failure_test.TestFailure: code(code_a)",
},
Expand All @@ -45,17 +45,17 @@ func TestFailure(t *testing.T) {
shouldNil: false,
wantCode: TestCodeB,
wantMessage: "xxx",
wantDebugs: []failure.Debug{{"zzz": true}},
wantDebugs: []failure.Debug{{"zzz": "true"}},
wantStackLine: 20,
wantError: "failure_test.TestFailure: code(1): failure_test.TestFailure: code(code_a)",
},
"overwrite": {
err: failure.Translate(base, TestCodeB, failure.Message("aaa"), failure.Debug{"bbb": 1}),
err: failure.Translate(base, TestCodeB, failure.Message("aaa"), failure.Debug{"bbb": "1"}),

shouldNil: false,
wantCode: TestCodeB,
wantMessage: "aaa",
wantDebugs: []failure.Debug{{"bbb": 1}, {"zzz": true}},
wantDebugs: []failure.Debug{{"bbb": "1"}, {"zzz": "true"}},
wantStackLine: 20,
wantError: "failure_test.TestFailure: code(1): failure_test.TestFailure: code(code_a)",
},
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestFailure(t *testing.T) {

func TestFailure_Format(t *testing.T) {
e1 := fmt.Errorf("yyy")
e2 := failure.Translate(e1, TestCodeA, failure.Message("xxx"), failure.Debug{"zzz": true})
e2 := failure.Translate(e1, TestCodeA, failure.Message("xxx"), failure.Debug{"zzz": "true"})
err := failure.Wrap(e2)

want := "failure_test.TestFailure_Format: failure_test.TestFailure_Format: code(code_a): yyy"
Expand Down
4 changes: 2 additions & 2 deletions wrapper.go
Expand Up @@ -73,7 +73,7 @@ func MessageOf(err error) (string, bool) {

// Debug is a key-value data appended to an error
// for debugging purpose.
type Debug map[string]interface{}
type Debug map[string]string

// WrapError implements the Wrapper interface.
func (d Debug) WrapError(err error) error {
Expand Down Expand Up @@ -238,7 +238,7 @@ func (f formatter) Format(s fmt.State, verb rune) {
case debugger:
debug := t.GetDebug()
for k, v := range debug {
fmt.Fprintf(s, " %s = %v\n", k, v)
fmt.Fprintf(s, " %s = %s\n", k, v)
}
case messenger:
fmt.Fprintf(s, " message(%q)\n", t.GetMessage())
Expand Down

0 comments on commit edf4ef2

Please sign in to comment.