1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError/error.go
Mritunjay Kumar Sharma b815caef5d
refactor cli code from pkg to cmd (#3591)
* refactor cli code from pkg to cmd

Signed-off-by: Mritunjay Sharma <mritunjaysharma394@gmail.com>

* fixes in imports

Signed-off-by: Mritunjay Sharma <mritunjaysharma394@gmail.com>

* fixes tests

Signed-off-by: Mritunjay Sharma <mritunjaysharma394@gmail.com>

* fixed conflicts

Signed-off-by: Mritunjay Sharma <mritunjaysharma394@gmail.com>

* moved non-commands to utils

Signed-off-by: Mritunjay Sharma <mritunjaysharma394@gmail.com>

Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com>
2022-04-14 12:20:18 +00:00

46 lines
919 B
Go

package sanitizederror
import (
"fmt"
"strings"
)
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()}
}
// NewWithError creates a new sanitized error with given message and error
func NewWithError(message string, err error) error {
if err == nil {
return customError{message: message}
}
msg := fmt.Sprintf("%s \nCause: %s", message, err.Error())
return customError{message: msg}
}
// IsErrorSanitized checks if the error is sanitized error
func IsErrorSanitized(err error) bool {
if _, ok := err.(customError); !ok {
return false
}
return true
}