sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/pkg/plank/error.go (about) 1 /* 2 Copyright 2020 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package plank 18 19 import ( 20 "errors" 21 "fmt" 22 ) 23 24 type nonRetryableError struct { 25 err error 26 } 27 28 func (ne nonRetryableError) Error() string { 29 return fmt.Sprintf("nonretryable error: %s", ne.err.Error()) 30 } 31 32 func (nonRetryableError) Is(err error) bool { 33 _, ok := err.(nonRetryableError) 34 return ok 35 } 36 37 // TerminalError wraps an error and return a nonRetryableError error 38 func TerminalError(err error) error { 39 return &nonRetryableError{err: err} 40 } 41 42 func IsTerminalError(err error) bool { 43 return errors.Is(err, nonRetryableError{}) 44 }