From 29869fad88479e77e0b24943d2e1cc1dad5eda7e Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 2 Aug 2026 07:58:17 +0000 Subject: [PATCH] fix: error on file arguments that match nothing filepath.Glob returns no matches and no error both for a glob that matches nothing and for a literal path that does not exist, so a typo'd filename was silently skipped: `kir typo.yaml` produced no output and exited 0. Treat an argument that resolves to zero files as an error naming that argument; Run then reports it and exits non-zero. The behavioral golden suite reflects this: TestCLI.MissingFile now exits 1 with the error on stderr. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Pc6NAURAqjU4LYJx93tgSC --- .../kir_test.TestCLI.MissingFile.exitcode.approved.txt | 2 +- .../kir_test.TestCLI.MissingFile.stderr.approved.txt | 1 + fileutil/fileutil.go | 9 +++++++++ fileutil/fileutil_test.go | 9 +++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/approvals/kir_test.TestCLI.MissingFile.exitcode.approved.txt b/approvals/kir_test.TestCLI.MissingFile.exitcode.approved.txt index c227083..56a6051 100644 --- a/approvals/kir_test.TestCLI.MissingFile.exitcode.approved.txt +++ b/approvals/kir_test.TestCLI.MissingFile.exitcode.approved.txt @@ -1 +1 @@ -0 \ No newline at end of file +1 \ No newline at end of file diff --git a/approvals/kir_test.TestCLI.MissingFile.stderr.approved.txt b/approvals/kir_test.TestCLI.MissingFile.stderr.approved.txt index e69de29..79b27b1 100644 --- a/approvals/kir_test.TestCLI.MissingFile.stderr.approved.txt +++ b/approvals/kir_test.TestCLI.MissingFile.stderr.approved.txt @@ -0,0 +1 @@ +error: no such file or match for "does-not-exist.yaml" diff --git a/fileutil/fileutil.go b/fileutil/fileutil.go index 1a590b1..b26325f 100644 --- a/fileutil/fileutil.go +++ b/fileutil/fileutil.go @@ -1,6 +1,7 @@ package fileutil import ( + "fmt" "os" "path/filepath" ) @@ -14,6 +15,14 @@ func FindFiles(args []string) ([]string, error) { return nil, err } + // filepath.Glob returns no matches and no error both for a glob + // pattern that matches nothing and for a literal path that does not + // exist. Either way the argument named nothing, which is almost + // always a typo; surface it instead of silently skipping it. + if len(matchedFiles) == 0 { + return nil, fmt.Errorf("no such file or match for %q", filePath) + } + for _, matchedFile := range matchedFiles { fileInfo, err := os.Stat(matchedFile) if err != nil { diff --git a/fileutil/fileutil_test.go b/fileutil/fileutil_test.go index 828ace3..4b97dc0 100644 --- a/fileutil/fileutil_test.go +++ b/fileutil/fileutil_test.go @@ -67,3 +67,12 @@ func TestFindFiles(t *testing.T) { }) } } + +// A path that names nothing (a typo'd or missing file) must be reported as an +// error rather than silently ignored. +func TestFindFilesMissing(t *testing.T) { + missing := filepath.Join(t.TempDir(), "does-not-exist.yaml") + if _, err := FindFiles([]string{missing}); err == nil { + t.Fatalf("FindFiles(%q) returned nil error for a missing path", missing) + } +}