Skip to content

Commit

Permalink
test: handle fs.Stat errors to prevent panics
Browse files Browse the repository at this point in the history
  • Loading branch information
brandondyck authored and shoenig committed Aug 19, 2024
1 parent c2ea984 commit 24ca481
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions internal/assertions/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,8 +983,13 @@ func FileExistsFS(system fs.FS, file string) (s string) {
s += bullet("error: %s\n", err)
return
}
if err != nil {
s = "got an unexpected error\n"
s += bullet("name: %s\n", file)
s += bullet("error: %s\n", err)
return
}

// other errors - file probably exists but cannot be read
if info.IsDir() {
s = "expected file but is a directory\n"
s += bullet("name: %s\n", file)
Expand Down Expand Up @@ -1016,7 +1021,12 @@ func DirExistsFS(system fs.FS, directory string) (s string) {
s += bullet("error: %s\n", err)
return
}
// other errors - directory probably exists but cannot be read
if err != nil {
s = "got an unexpected error\n"
s += bullet("name: %s\n", directory)
s += bullet("error: %s\n", err)
return
}
if !info.IsDir() {
s = "expected directory but is a file\n"
s += bullet("name: %s\n", directory)
Expand Down

0 comments on commit 24ca481

Please sign in to comment.