mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
chore: Standardise Error Codes (#286)
* fix: Misc error handling fixes * fix: Sandbox error translation
This commit is contained in:
+12
-4
@@ -9,10 +9,10 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/safedep/pmg/internal/ui"
|
||||
pmgsandbox "github.com/safedep/pmg/sandbox"
|
||||
"github.com/safedep/dry/usefulerror"
|
||||
"github.com/safedep/pmg/errcodes"
|
||||
"github.com/safedep/pmg/internal/ui"
|
||||
pmgsandbox "github.com/safedep/pmg/sandbox"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -70,7 +70,7 @@ func wrapUseful(err error, code, help string) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if _, ok := usefulerror.AsUsefulError(err); ok {
|
||||
if hasUsefulError(err) {
|
||||
return err
|
||||
}
|
||||
return usefulerror.NewUsefulError().
|
||||
@@ -84,7 +84,7 @@ func profileLoadError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if _, ok := usefulerror.AsUsefulError(err); ok {
|
||||
if hasUsefulError(err) {
|
||||
return err
|
||||
}
|
||||
switch {
|
||||
@@ -99,6 +99,14 @@ func profileLoadError(err error) error {
|
||||
"Failed to load the sandbox profile. Run with --verbose for the underlying cause.")
|
||||
}
|
||||
|
||||
func hasUsefulError(err error) bool {
|
||||
// AsUsefulError also runs global converters for plain errors like
|
||||
// fs.ErrPermission. Contextual wrappers must only skip errors that already
|
||||
// carry UsefulError details, otherwise generic converters hide command help.
|
||||
var usefulErr usefulerror.UsefulError
|
||||
return errors.As(err, &usefulErr)
|
||||
}
|
||||
|
||||
func registryInitError(err error) error {
|
||||
return wrapUseful(err, ioErrorCode(err, errcodes.Unknown),
|
||||
"Failed to initialise the sandbox profile registry. Run with --verbose for details.")
|
||||
|
||||
Reference in New Issue
Block a user