From eaf7e3597b3dfb64f06df2e55f0647e519bc4636 Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Mon, 12 Feb 2024 08:58:32 -0300 Subject: [PATCH] (wip) --- pkg/cmd/time-entry/util/defaults/defaults.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/cmd/time-entry/util/defaults/defaults.go b/pkg/cmd/time-entry/util/defaults/defaults.go index ee4b2346..9568cd65 100644 --- a/pkg/cmd/time-entry/util/defaults/defaults.go +++ b/pkg/cmd/time-entry/util/defaults/defaults.go @@ -67,6 +67,10 @@ type timeEntryDefaults struct { DefaultTimeEntry } +// FailedToOpenErr error returned when failing to open file without an explicit +// error +var FailedToOpenErr = errors.New("failed to open file") + // Write persists the default values to the folder func (t *timeEntryDefaults) Write(d DefaultTimeEntry) error { println(filepath.Join(t.Dir, t.Filename)) @@ -74,6 +78,12 @@ func (t *timeEntryDefaults) Write(d DefaultTimeEntry) error { if err != nil { return err } + + if f == nil { + return FailedToOpenErr + + } + defer f.Close() if strings.HasSuffix(f.Name(), "json") { @@ -111,6 +121,11 @@ func (t *timeEntryDefaults) Read() (DefaultTimeEntry, error) { dir = nDir continue } + + if f == nil { + return d, FailedToOpenErr + + } defer f.Close() if strings.HasSuffix(f.Name(), "json") {