Skip to content

Commit

Permalink
A new WalkDir error.
Browse files Browse the repository at this point in the history
It is returned when an options flag is used after the scan directories.

Fixed a test causing a panic.

Fixed missing import from Windows test.
  • Loading branch information
bengarrett committed Feb 3, 2022
1 parent 179adb4 commit 000aa8f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/example_win_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ package zipcmt_test
import (
"fmt"
"log"

zipcmt "github.com/bengarrett/zipcmt/lib"
)

func ExampleConfig_clean() {
Expand Down
13 changes: 12 additions & 1 deletion lib/zipcmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,19 @@ func (c *Config) WalkDir(root string) error { // nolint: cyclop,funlen,gocognit
}
return err
})
return walkErrs(root, err)
}

func walkErrs(root string, err error) error {
var pathError *os.PathError
if errors.As(err, &pathError) {
if root != "" && root[:1] == "-" {
return fmt.Errorf("detected an options flag, "+
"all the directories to scan must be listed after any option flags: %s", root)
}
}
if err != nil {
return fmt.Errorf("walk directory: %s, %w", root, err)
return fmt.Errorf("walk directory: %s, %w %T", root, err, err)
}
return nil
}
Expand Down

0 comments on commit 000aa8f

Please sign in to comment.