Skip to content

Ignore fs.WalkDir errors in FindFiles #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add error case to FindFiles tests
  • Loading branch information
parkerduckworth committed Jun 3, 2022
commit 640a46ba220453bbc15a765b41ee2e971655f27d
19 changes: 19 additions & 0 deletions script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,25 @@ func TestFindFiles_RecursesIntoSubdirectories(t *testing.T) {
}
}

// FindFiles has been updated to ignore all errors
// see [github issue #99]
// (https://github.com/bitfield/script/issues/99)
func TestFindFiles_FailsSilently(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "fails silently" could be misinterpreted, couldn't it? Like "fails" suggests it's not working properly. What about something like:

Suggested change
func TestFindFiles_FailsSilently(t *testing.T) {
func TestFindFiles_ReturnsEmptyPipeAndNoErrorForNonexistentPath(t *testing.T) {

But I'm not convinced this is the right behaviour, actually. I am convinced that if there's some error from fs.WalkDir's traversal, we should ignore that. But if the user has asked us to FindFiles starting from some root that doesn't exist, I think that should be an error. Would you want to know that, as the programmer? I would.

t.Parallel()
want := "\n"
p := script.FindFiles("testdata/nonexistent")
if p.Error() != nil {
t.Fatal(p.Error())
}
got, err := p.String()
if err != nil {
t.Fatal(err)
}
if want != got {
t.Error(cmp.Diff(want, got))
}
}

func TestIfExists_ProducesErrorPlusNoOutputForNonexistentFile(t *testing.T) {
t.Parallel()
want := ""
Expand Down