mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-27 05:23:06 +00:00
Namespace restricted mode (#147)
This commit is contained in:
committed by
GitHub
parent
dea223bfe1
commit
04579eb03c
29
cli/errormessage/errormessage.go
Normal file
29
cli/errormessage/errormessage.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package errormessage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
regexpsyntax "regexp/syntax"
|
||||
|
||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
)
|
||||
|
||||
// formatError wraps error with a detailed message that is meant for the user.
|
||||
// While the errors are meant to be displayed, they are not meant to be exported as classes outsite of CLI.
|
||||
func FormatError(err error) error {
|
||||
var errorNew error
|
||||
if k8serrors.IsForbidden(err) {
|
||||
errorNew = fmt.Errorf("Insufficient permissions: %w. Supply the required permission or control Mizu's access to namespaces by setting MizuNamespace in the config file or setting the tapped namespace with --set mizu-namespace=<NAMEPSACE>.", err)
|
||||
} else if syntaxError, isSyntaxError := asRegexSyntaxError(err); isSyntaxError {
|
||||
errorNew = fmt.Errorf("Regex %s is invalid: %w", syntaxError.Expr, err)
|
||||
} else {
|
||||
errorNew = err
|
||||
}
|
||||
|
||||
return errorNew
|
||||
}
|
||||
|
||||
func asRegexSyntaxError(err error) (*regexpsyntax.Error, bool) {
|
||||
var syntaxError *regexpsyntax.Error
|
||||
return syntaxError, errors.As(err, &syntaxError)
|
||||
}
|
Reference in New Issue
Block a user