Skip to content

Commit

Permalink
If a file's missing, don't panic but show error
Browse files Browse the repository at this point in the history
Dumping a stack trace on a typo is a bad user experience.
  • Loading branch information
hrs committed Jun 20, 2023
1 parent eea93fa commit 61deb08
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion corpus/corpus.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package corpus

import (
"errors"
"fmt"
"io/fs"
"log"
"math"
"os"
"path/filepath"
Expand Down Expand Up @@ -44,7 +46,11 @@ func ParseCorpus(query *Document, paths []string, config *Config) *Corpus {
for _, path := range paths {
err := filepath.WalkDir(path, func(xpath string, xinfo fs.DirEntry, xerr error) error {
if xerr != nil {
panic(xerr)
if errors.Is(xerr, os.ErrNotExist) {
log.Fatal("no such file or directory: ", path)
} else {
panic(xerr)
}
}

// Don't parse directories or symlinks (or the queried file, if so configured)
Expand Down

0 comments on commit 61deb08

Please # to comment.