From 8da0f00a0067134a012c3abf0a2ba834f080a51d Mon Sep 17 00:00:00 2001 From: Jason Kingsbury Date: Thu, 7 Mar 2024 14:46:44 +0000 Subject: [PATCH 1/2] Check for non-nil error in FindTemplates --- cmd/templ/processor/processor.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/templ/processor/processor.go b/cmd/templ/processor/processor.go index 4908716dd..ab9552415 100644 --- a/cmd/templ/processor/processor.go +++ b/cmd/templ/processor/processor.go @@ -43,6 +43,9 @@ func shouldSkipDir(dir string) bool { func FindTemplates(srcPath string, output chan<- string) (err error) { return filepath.Walk(srcPath, func(currentPath string, info fs.FileInfo, err error) error { + if err != nil { + return err + } if info.IsDir() && shouldSkipDir(currentPath) { return filepath.SkipDir } From 1fd33c67380b26e780872d78ebd57818a7047e36 Mon Sep 17 00:00:00 2001 From: Adrian Hesketh Date: Thu, 7 Mar 2024 18:02:26 +0000 Subject: [PATCH 2/2] feat: add test --- cmd/templ/processor/processor_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 cmd/templ/processor/processor_test.go diff --git a/cmd/templ/processor/processor_test.go b/cmd/templ/processor/processor_test.go new file mode 100644 index 000000000..438ac2dd7 --- /dev/null +++ b/cmd/templ/processor/processor_test.go @@ -0,0 +1,19 @@ +package processor + +import ( + "os" + "testing" +) + +func TestFindTemplates(t *testing.T) { + t.Run("returns an error if the directory does not exist", func(t *testing.T) { + output := make(chan string) + err := FindTemplates("nonexistent", output) + if err == nil { + t.Fatal("expected error, but got nil") + } + if !os.IsNotExist(err) { + t.Fatalf("expected os.IsNotExist(err) to be true, but got: %v", err) + } + }) +}