mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
refactor : Refactor error handling to use dry/usefulerror (#283)
* update the go.sum Signed-off-by: DivyanshuVortex <divyanshuchandra9027@gmail.com> * migrate most of the files to dry errors Signed-off-by: DivyanshuVortex <divyanshuchandra9027@gmail.com> * update the rest of the files Signed-off-by: DivyanshuVortex <divyanshuchandra9027@gmail.com> * fixs the review comments Signed-off-by: DivyanshuVortex <divyanshuchandra9027@gmail.com> * chores Signed-off-by: DivyanshuVortex <divyanshuchandra9027@gmail.com> --------- Signed-off-by: DivyanshuVortex <divyanshuchandra9027@gmail.com> Co-authored-by: Abhisek Datta <abhisek.datta@gmail.com>
This commit is contained in:
co-authored by
Abhisek Datta
parent
e5fe0df82e
commit
20e01d5cae
@@ -8,7 +8,8 @@ import (
|
||||
|
||||
"github.com/safedep/pmg/internal/ui"
|
||||
pmgsandbox "github.com/safedep/pmg/sandbox"
|
||||
"github.com/safedep/pmg/usefulerror"
|
||||
"github.com/safedep/dry/usefulerror"
|
||||
"github.com/safedep/pmg/errcodes"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -27,7 +28,7 @@ func (e *violationsListFailError) ExitCode() int { return ExitCodeViolationsList
|
||||
|
||||
func newViolationsListFailError(code, msg, help string) *violationsListFailError {
|
||||
return &violationsListFailError{
|
||||
UsefulError: usefulerror.Useful().
|
||||
UsefulError: usefulerror.NewUsefulError().
|
||||
WithCode(code).
|
||||
WithHumanError(msg).
|
||||
WithHelp(help).
|
||||
@@ -61,7 +62,7 @@ func newViolationsListCommand(factory cacheFactory) *cobra.Command {
|
||||
func runViolationsList(out, errOut io.Writer, opts *violationsListOptions, factory cacheFactory) error {
|
||||
if opts.limit < 0 {
|
||||
return newViolationsListFailError(
|
||||
usefulerror.ErrCodeInvalidArgument,
|
||||
errcodes.InvalidArgument,
|
||||
fmt.Sprintf("invalid --limit %d (must be >= 0)", opts.limit),
|
||||
"Pass --limit 0 to show all entries, or a positive limit.",
|
||||
)
|
||||
@@ -71,7 +72,7 @@ func runViolationsList(out, errOut io.Writer, opts *violationsListOptions, facto
|
||||
entries, err := cache.List()
|
||||
if err != nil {
|
||||
return newViolationsListFailError(
|
||||
usefulerror.ErrCodeUnknown,
|
||||
errcodes.Unknown,
|
||||
fmt.Sprintf("read cache: %v", err),
|
||||
"Check the sandbox violation cache directory and retry.",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user