mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-09-13 13:22:01 +00:00
🔨 Move cli
folder contents into project root (#1253)
* Remove `logger` module * Remove `shared` module * Move `cli` folder contents into project root * Fix linter * Change the module name from `github.com/kubeshark/kubeshark/cli` to `github.com/kubeshark/kubeshark` * Set the default `Makefile` rule to `build` * Add `lint` rule * Fix the linter errors
This commit is contained in:
37
errormessage/errormessage.go
Normal file
37
errormessage/errormessage.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package errormessage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
regexpsyntax "regexp/syntax"
|
||||
|
||||
"github.com/kubeshark/kubeshark/config"
|
||||
|
||||
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 Kubeshark's access to namespaces by setting %s "+
|
||||
"in the config file or setting the tapped namespace with --%s %s=<NAMEPSACE>",
|
||||
err,
|
||||
config.KubesharkResourcesNamespaceConfigName,
|
||||
config.SetCommandName,
|
||||
config.KubesharkResourcesNamespaceConfigName)
|
||||
} 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