diff --git a/pkg/reconcile/reconcile.go b/pkg/reconcile/reconcile.go index d51cfc34ab..4c8f8357a5 100644 --- a/pkg/reconcile/reconcile.go +++ b/pkg/reconcile/reconcile.go @@ -112,11 +112,15 @@ type terminalError struct { err error } +// This function will return nil if te.err is nil. func (te *terminalError) Unwrap() error { return te.err } func (te *terminalError) Error() string { + if te.err == nil { + return "nil terminal error" + } return "terminal error: " + te.err.Error() } diff --git a/pkg/reconcile/reconcile_test.go b/pkg/reconcile/reconcile_test.go index b5660f1b4f..9373d5ed5c 100644 --- a/pkg/reconcile/reconcile_test.go +++ b/pkg/reconcile/reconcile_test.go @@ -96,5 +96,10 @@ var _ = Describe("reconcile", func() { Expect(apierrors.IsGone(terminalError)).To(BeTrue()) }) + + It("should handle nil terminal errors properly", func() { + err := reconcile.TerminalError(nil) + Expect(err.Error()).To(Equal("nil terminal error")) + }) }) })