Skip to content

Commit 357eb83

Browse files
authored
Merge pull request #2438 from solo-io/nil-terminal-error-fix
🐛 Fix TerminalError(nil).Error() panic
2 parents dbcf380 + e3ad494 commit 357eb83

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pkg/reconcile/reconcile.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,15 @@ type terminalError struct {
112112
err error
113113
}
114114

115+
// This function will return nil if te.err is nil.
115116
func (te *terminalError) Unwrap() error {
116117
return te.err
117118
}
118119

119120
func (te *terminalError) Error() string {
121+
if te.err == nil {
122+
return "nil terminal error"
123+
}
120124
return "terminal error: " + te.err.Error()
121125
}
122126

pkg/reconcile/reconcile_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,10 @@ var _ = Describe("reconcile", func() {
9696

9797
Expect(apierrors.IsGone(terminalError)).To(BeTrue())
9898
})
99+
100+
It("should handle nil terminal errors properly", func() {
101+
err := reconcile.TerminalError(nil)
102+
Expect(err.Error()).To(Equal("nil terminal error"))
103+
})
99104
})
100105
})

0 commit comments

Comments
 (0)