From 66284cfbecee9f357fca553874e7a319426349af Mon Sep 17 00:00:00 2001 From: NiloCK Date: Wed, 2 Jul 2025 15:37:35 -0300 Subject: [PATCH] return empty items list for failed file lookup closes #51 --- tui/tui.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tui/tui.go b/tui/tui.go index f77f141..d75cb9c 100644 --- a/tui/tui.go +++ b/tui/tui.go @@ -451,24 +451,24 @@ func (t tui) Init() tea.Cmd { return tick() } func getItems(file string) []*tuido.Item { items := []*tuido.Item{} - f, err := os.Open(file) - defer f.Close() - - if err != nil { - panic(err) - } - - scanner := bufio.NewScanner(f) - line := 1 - for scanner.Scan() { - if tuido.IsTuido(scanner.Text()) { - item := tuido.New(file, line, scanner.Text()) - items = append(items, &item) + if f, err := os.Open(file); err != nil { + f.Close() + return items + } else { + defer f.Close() + + scanner := bufio.NewScanner(f) + line := 1 + for scanner.Scan() { + if tuido.IsTuido(scanner.Text()) { + item := tuido.New(file, line, scanner.Text()) + items = append(items, &item) + } + line++ } - line++ - } - return items + return items + } } func getFiles(wd string, extensions []string) []string {