diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e410a29 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ + .idea \ No newline at end of file diff --git a/.tools-version b/.tools-version new file mode 100644 index 0000000..3990909 --- /dev/null +++ b/.tools-version @@ -0,0 +1 @@ +golang 1.18.4 \ No newline at end of file diff --git a/flatten.go b/flatten.go index 3612005..2b63908 100644 --- a/flatten.go +++ b/flatten.go @@ -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() diff --git a/tests/flatten_test.go b/tests/flatten_test.go index da7142c..358e556 100644 --- a/tests/flatten_test.go +++ b/tests/flatten_test.go @@ -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) @@ -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) diff --git a/tests/format_test.go b/tests/format_test.go index 82766f6..0fb2575 100644 --- a/tests/format_test.go +++ b/tests/format_test.go @@ -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)) @@ -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))