Skip to content

Commit

Permalink
refactor: improve error handling in directory and file analysis
Browse files Browse the repository at this point in the history
- Replaced direct comparison of error types with errors.Is for better error handling in both directory.go and file.go.
- This change enhances the clarity and robustness of cancellation handling during analysis processes, ensuring that user-initiated cancellations are managed more effectively.
  • Loading branch information
tphakala committed Jan 19, 2025
1 parent 57d555e commit 3060a6b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmd/directory/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package directory

import (
"context"
"errors"
"fmt"
"os"
"os/signal"
Expand Down Expand Up @@ -46,7 +47,7 @@ func Command(settings *conf.Settings) *cobra.Command {
settings.Input.Path = args[0]
err := analysis.DirectoryAnalysis(settings, ctx)
if err != nil {
if err == context.Canceled {
if errors.Is(err, context.Canceled) {
return nil
}
return err
Expand Down
3 changes: 2 additions & 1 deletion cmd/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package file

import (
"context"
"errors"
"fmt"
"os"
"os/signal"
Expand Down Expand Up @@ -40,7 +41,7 @@ func Command(settings *conf.Settings) *cobra.Command {
// Input file path is the first argument
settings.Input.Path = args[0]
err := analysis.FileAnalysis(settings, ctx)
if err == context.Canceled {
if errors.Is(err, context.Canceled) {
// Return nil for user-initiated cancellation
return nil
}
Expand Down

0 comments on commit 3060a6b

Please sign in to comment.