From 18b8f8870f2e74f03d63f087bc62755ab6ab2e9c Mon Sep 17 00:00:00 2001 From: Srigovind Nayak <5201843+konidev20@users.noreply.github.com> Date: Sat, 19 Apr 2025 14:20:52 +0530 Subject: [PATCH] tests: add tests for preserving underlying errors --- internal/errors/fatal_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/errors/fatal_test.go b/internal/errors/fatal_test.go index 41da8dee7..da966bbaa 100644 --- a/internal/errors/fatal_test.go +++ b/internal/errors/fatal_test.go @@ -20,3 +20,23 @@ func TestFatal(t *testing.T) { } } } + +func TestFatalErrorWrapping(t *testing.T) { + underlying := errors.New("underlying error") + fatal := errors.Fatalf("fatal error: %v", underlying) + + // Test that the fatal error message is preserved + if fatal.Error() != "Fatal: fatal error: underlying error" { + t.Errorf("unexpected error message: %v", fatal.Error()) + } + + // Test that we can unwrap to get the underlying error + if !errors.Is(fatal, underlying) { + t.Error("fatal error should wrap the underlying error") + } + + // Test that the error is marked as fatal + if !errors.IsFatal(fatal) { + t.Error("error should be marked as fatal") + } +}