Skip to content

Commit

Permalink
Update error format (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat authored Oct 31, 2020
1 parent bd4a4ec commit 5f5dbac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Error struct {
}

func (e *Error) Error() string {
return fmt.Sprintf("%s (%s:%d): %s", e.Failure, filepath.Base(e.File), e.Line, e.Err.Error())
return fmt.Sprintf("%s [%s:%d]: %s", e.Failure, filepath.Base(e.File), e.Line, e.Err.Error())
}

// Unwrap returns the reason of the failure.
Expand Down
5 changes: 4 additions & 1 deletion error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ func TestError(t *testing.T) {
errBase := errors.New("an error")
errOther := errors.New("an another error")
errChained := wrapErrorf(errBase, "info")
t.Log(`wrapErrorf(errBase, "info"):`, errChained)
errChained2 := wrapError(errBase, "info")
t.Log(`wrapError(errBase, "info"):`, errChained2)
errDoubleChained := wrapErrorf(errChained, "info")
t.Log(`wrapErrorf(errChained, "info"):`, errDoubleChained)
errChainedNil := wrapErrorf(nil, "info")
errChainedOther := wrapErrorf(errOther, "info")
err112Chained := wrapErrorf(&dummyError{errBase}, "info")
err112Nil := wrapErrorf(&dummyError{nil}, "info")
errStrRegex := regexp.MustCompile(`^info \(error_test\.go:[0-9]+\): an error$`)
errStrRegex := regexp.MustCompile(`^info \[error_test\.go:[0-9]+\]: an error$`)

t.Run("ErrorsIs", func(t *testing.T) {
if !errs.Is(errChained, errBase) {
Expand Down

0 comments on commit 5f5dbac

Please sign in to comment.