From 9b111d1fa70073d64bd174311744502f55a2a411 Mon Sep 17 00:00:00 2001 From: Ben Kraft Date: Wed, 9 Feb 2022 16:32:58 -0800 Subject: [PATCH] Reject a glob that matches no files 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. 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 ``` --- generate/parse.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/generate/parse.go b/generate/parse.go index 7b2ac5e5..a9fe07ac 100644 --- a/generate/parse.go +++ b/generate/parse.go @@ -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 }