Skip to content

Commit

Permalink
Reject a glob that matches no files (#173)
Browse files Browse the repository at this point in the history
The most important case here is if your glob isn't even a glob, it's
just a filename.  But even if it was a glob, it's probably a mistake;
you'll probably end up with a confusing error due to an empty schema, or
a slightly less confusing error due to not having any operations.
Instead, let's just say outright that your glob didn't match any files.

Fixes #146.

Test plan:
This was a bit annoying to test via snapshot, so I just tested it
manually by modifying the example to use a glob that didn't match any
files, first for the schema then for the operations, and got errors like
```
bogus*.graphql did not match any files
exit status 1
example/main.go:68: running "go": exit status 1
```
  • Loading branch information
benjaminjkraft authored Feb 10, 2022
1 parent 67f2575 commit 49a26af
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions generate/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func expandFilenames(globs []string) ([]string, error) {
if err != nil {
return nil, errorf(nil, "can't expand file-glob %v: %v", glob, err)
}
if len(matches) == 0 {
return nil, errorf(nil, "%v did not match any files", glob)
}
for _, match := range matches {
uniqFilenames[match] = true
}
Expand Down

0 comments on commit 49a26af

Please sign in to comment.