Skip to content

Commit

Permalink
refactor: error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
umlx5h committed Jan 12, 2024
1 parent b1e05e0 commit 21e8d65
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
12 changes: 8 additions & 4 deletions internal/cmd/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,13 @@ func findCmdRun(args []string, opts findOptions) error {
trash.WithTrashDir(opts.trashDir),
)
if err := box.Open(); err != nil {
return err
// no error only remove mode (consider executing via batch)
if opts.doRemove && errors.Is(err, trash.ErrNotFound) {
fmt.Printf("do nothing: %s\n", err)
return nil
} else {
return err
}
}

listFiles(box.Files, box.GetSize, opts.showTrashPath)
Expand All @@ -212,9 +218,7 @@ func findCmdRun(args []string, opts findOptions) error {
if !opts.force && isTerminal && !tui.BoolPrompt("Are you sure you want to remove PERMENANTLY? ") {
return errors.New("do nothing")
}
if err := doRemove(box.Files); err != nil {
return err
}
doRemove(box.Files)

} else if opts.doRestore {
if opts.restoreTo != "" {
Expand Down
9 changes: 7 additions & 2 deletions internal/cmd/metafix.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ func metafixCmdRun(opts metafixOptions) error {
trash.WithSortBy(trash.SortByName),
)
if err := box.Open(); err != nil {
return err
if errors.Is(err, trash.ErrNotFound) {
fmt.Printf("do nothing: %s\n", err)
return nil
} else {
return err
}
}

if len(box.OrphanMeta) == 0 {
fmt.Println("Not found invalid metadata")
fmt.Println("not found invalid metadata")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func summaryCmdRun(_ summaryOptions) error {
totalItem += item
}

if len(box.FilesByTrashDir) > 1 {
if len(box.TrashDirs) > 1 {
fmt.Printf("\n[total]\n")
fmt.Printf("item: %d\n", totalItem)
fmt.Printf("size: %s\n", humanize.Bytes(uint64(totalSize)))
Expand Down

0 comments on commit 21e8d65

Please sign in to comment.