From 3094f5c857d6bc4ba5811678c92125eebca6f2e8 Mon Sep 17 00:00:00 2001 From: Patrick DeVivo Date: Tue, 15 Feb 2022 16:16:43 -0500 Subject: [PATCH] fix: error handling for summarize commands --- cmd/summarize/blame/blame.go | 6 +++++- cmd/summarize/commits/commits.go | 6 +++++- cmd/summarize_blame.go | 6 +++++- cmd/summarize_commits.go | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/cmd/summarize/blame/blame.go b/cmd/summarize/blame/blame.go index 0442b0df..6c8de2f9 100644 --- a/cmd/summarize/blame/blame.go +++ b/cmd/summarize/blame/blame.go @@ -467,5 +467,9 @@ func (t *TermUI) PrintJSON() string { } func (t *TermUI) Close() error { - return t.db.Close() + defer t.db.Close() + if t.err != nil { + return t.err + } + return nil } diff --git a/cmd/summarize/commits/commits.go b/cmd/summarize/commits/commits.go index 985ec490..d330175c 100644 --- a/cmd/summarize/commits/commits.go +++ b/cmd/summarize/commits/commits.go @@ -435,5 +435,9 @@ func (t *TermUI) PrintJSON() string { } func (t *TermUI) Close() error { - return t.db.Close() + defer t.db.Close() + if t.err != nil { + return t.err + } + return nil } diff --git a/cmd/summarize_blame.go b/cmd/summarize_blame.go index ba3d928a..11b03716 100644 --- a/cmd/summarize_blame.go +++ b/cmd/summarize_blame.go @@ -33,7 +33,11 @@ Use '%' to match all file paths or as a wildcard (e.g. '%.go' for all .go files) if ui, err = blame.NewTermUI(pathPattern); err != nil { handleExitError(err) } - defer ui.Close() + defer func() { + if err := ui.Close(); err != nil { + handleExitError(err) + } + }() if blameOutputJSON { fmt.Println(ui.PrintJSON()) diff --git a/cmd/summarize_commits.go b/cmd/summarize_commits.go index 4c7e4a5e..ffc2012a 100644 --- a/cmd/summarize_commits.go +++ b/cmd/summarize_commits.go @@ -41,7 +41,11 @@ Read more here: https://sqlite.org/lang_expr.html#the_like_glob_regexp_and_match if ui, err = commits.NewTermUI(pathPattern, summarizeDateFilterStart, summarizeDateFilterEnd); err != nil { handleExitError(err) } - defer ui.Close() + defer func() { + if err := ui.Close(); err != nil { + handleExitError(err) + } + }() if summarizeOutputJSON { fmt.Println(ui.PrintJSON())