1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-09 09:26:54 +00:00
kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError/error.go

47 lines
919 B
Go
Raw Normal View History

2020-11-17 13:07:30 -08:00
package sanitizederror
2020-03-06 03:00:18 +05:30
import (
"fmt"
"strings"
)
2020-03-06 03:00:18 +05:30
type customError struct {
message string
}
func (c customError) Error() string {
return c.message
}
func New(msg string) error {
return customError{message: msg}
}
func NewWithErrors(message string, errors []error) error {
bldr := strings.Builder{}
bldr.WriteString(message + "\n")
for _, err := range errors {
bldr.WriteString(err.Error() + "\n")
}
return customError{message: bldr.String()}
2020-03-06 03:00:18 +05:30
}
2020-11-17 13:07:30 -08:00
// NewWithError creates a new sanitized error with given message and error
func NewWithError(message string, err error) error {
2020-07-03 17:42:08 -07:00
if err == nil {
return customError{message: message}
}
msg := fmt.Sprintf("%s \nCause: %s", message, err.Error())
return customError{message: msg}
}
2020-11-17 13:07:30 -08:00
// IsErrorSanitized checks if the error is sanitized error
2020-03-06 03:00:18 +05:30
func IsErrorSanitized(err error) bool {
if _, ok := err.(customError); !ok {
return false
}
return true
}