From 09b5e1f69fd75d25e3b69e0f3d5bd720bed24d67 Mon Sep 17 00:00:00 2001 From: ptdewey Date: Wed, 27 Nov 2024 22:13:37 -0500 Subject: [PATCH] fix: prevent panic in case of nonexistent notes directory path in config file --- internal/daemon/watcher.go | 5 +++++ internal/documents/corpus.go | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/internal/daemon/watcher.go b/internal/daemon/watcher.go index 56888f1..f93589a 100644 --- a/internal/daemon/watcher.go +++ b/internal/daemon/watcher.go @@ -25,6 +25,11 @@ func runNotesDirsWatcher(dirs ...string) error { dirIgnores := config.IgnoredDirectories() for _, dir := range dirs { + if _, err := os.Stat(dir); err != nil { + log.Printf("Error creating watcher on directory '%s': %v\n", dir, err) + continue + } + // TODO: add oolong ignore system to blacklist certain subdirs/files if err = filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { if !d.IsDir() { diff --git a/internal/documents/corpus.go b/internal/documents/corpus.go index 2f95447..5b9da8f 100644 --- a/internal/documents/corpus.go +++ b/internal/documents/corpus.go @@ -4,6 +4,7 @@ import ( "errors" "io/fs" "log" + "os" "path/filepath" "slices" "sync" @@ -41,6 +42,11 @@ func ReadNotesDirs() error { docs := []*Document{} for _, dir := range config.NotesDirPaths() { + if _, err := os.Stat(dir); err != nil { + log.Printf("Error reading directory '%s': %v\n", dir, err) + continue + } + // extract all note file paths from notes directory paths := []string{} // TODO: add oolong ignore system to blacklist certain subdirs/files