Skip to content

Commit

Permalink
Merge pull request #2443 from sheidkamp/terminal-error-panic-backport…
Browse files Browse the repository at this point in the history
…-to-v0.15

[release-0.15] 🐛 Fix TerminalError(nil).Error() panic
  • Loading branch information
k8s-ci-robot committed Aug 8, 2023
2 parents 40203bf + 84525cc commit 0269522
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/reconcile/reconcile.go
Expand Up @@ -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()
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/reconcile/reconcile_test.go
Expand Up @@ -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"))
})
})
})

0 comments on commit 0269522

Please sign in to comment.