From a1b0863e7675457602ce19214577bc4b5a8fd00b Mon Sep 17 00:00:00 2001 From: Raghav Muddur Date: Tue, 5 Apr 2022 12:57:42 -0700 Subject: [PATCH] Add `New` method to `TerminalError` (#82) This method helps to throw terminal error from the controller. Controller code can throw errors like ``` if *latestStatus == "create-failed" { return nil, ackerr.TerminalError.New(errors.New("cluster cannot be updated as its status is not 'available'.")) } ``` Code generator changes - https://github.com/aws-controllers-k8s/code-generator/pull/318 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. --- pkg/errors/error.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/errors/error.go b/pkg/errors/error.go index b89628d..d413e9b 100644 --- a/pkg/errors/error.go +++ b/pkg/errors/error.go @@ -92,6 +92,10 @@ type TerminalError struct { err error } +func (e TerminalError) New(terminalError error) *TerminalError { + return &TerminalError{err: terminalError} +} + func (e TerminalError) Error() string { if e.err == nil { return ""