sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/pkg/crier/reporters/criercommonlib/errors.go (about) 1 /* 2 Copyright 2022 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 criercommonlib contains shared lib used by reporters 18 package criercommonlib 19 20 import ( 21 "errors" 22 "fmt" 23 ) 24 25 type userError struct { 26 err error 27 } 28 29 func (ue userError) Error() string { 30 return fmt.Sprintf("this is a user error: %s", ue.err.Error()) 31 } 32 33 func (userError) Is(err error) bool { 34 _, ok := err.(userError) 35 return ok 36 } 37 38 // UserError wraps an error and return a userError error. 39 func UserError(err error) error { 40 return &userError{err: err} 41 } 42 43 // IsUserError checks whether the returned error is a user error. 44 func IsUserError(err error) bool { 45 return errors.Is(err, userError{}) 46 }