Skip to content

Commit

Permalink
fix: use fault.new location for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
matdurand authored and Southclaws committed May 30, 2023
1 parent fd61d1c commit 17181ef
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
1 change: 1 addition & 0 deletions .tools-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
golang 1.18.4
8 changes: 8 additions & 0 deletions flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ func Flatten(err error) Chain {
case *container:
lastLocation = unwrapped.location

case *fundamental:
f = append([]Step{{
Location: unwrapped.location,
Message: err.Error(),
}}, f...)

lastLocation = ""

default:
message := err.Error()

Expand Down
4 changes: 2 additions & 2 deletions tests/flatten_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestFlattenFaultSentinelError(t *testing.T) {

e0 := chain[0]
a.Equal("fault sentinel error", e0.Message)
a.Contains(e0.Location, "test_callers.go:29")
a.Contains(e0.Location, "root.go:15")

e1 := chain[1]
a.Equal("failed to call function", e1.Message)
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestFlattenFaultInlineError(t *testing.T) {

e0 := chain[0]
a.Equal("fault root cause error", e0.Message)
a.Contains(e0.Location, "test_callers.go:29")
a.Contains(e0.Location, "root.go:28")

e1 := chain[1]
a.Equal("failed to call function", e1.Message)
Expand Down
4 changes: 2 additions & 2 deletions tests/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestFormatFaultSentinelError(t *testing.T) {
a.Equal("failed to call function: fault sentinel error", fmt.Sprintf("%s", err))
a.Equal("failed to call function: fault sentinel error", fmt.Sprintf("%v", err))
a.Regexp(`fault sentinel error
\s+.+fault/tests/test_callers.go:29
\s+.+fault/tests/root.go:15
failed to call function
\s+.+fault/tests/test_callers.go:20
`, fmt.Sprintf("%+v", err))
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestFormatFaultInlineError(t *testing.T) {
a.Equal("failed to call function: fault root cause error", fmt.Sprintf("%s", err))
a.Equal("failed to call function: fault root cause error", fmt.Sprintf("%v", err))
a.Regexp(`fault root cause error
\s+.+fault/tests/test_callers.go:29
\s+.+fault/tests/root.go:28
failed to call function
\s+.+fault/tests/test_callers.go:20
`, fmt.Sprintf("%+v", err))
Expand Down

0 comments on commit 17181ef

Please sign in to comment.