From 41e4e4a5f32a46f78879c5daacd781309546c3c2 Mon Sep 17 00:00:00 2001 From: Boris Bera Date: Thu, 17 Oct 2024 07:49:45 -0400 Subject: [PATCH] fix(cron): crash when errors are encountered during a backup (#403) --- internal/cron.go | 12 +++++++++++- internal/location.go | 6 +++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/cron.go b/internal/cron.go index 56ae3d5..055e192 100644 --- a/internal/cron.go +++ b/internal/cron.go @@ -1,12 +1,22 @@ package internal +import ( + "errors" + "fmt" +) + func RunCron() error { c := GetConfig() + var errs []error for name, l := range c.Locations { l.name = name if err := l.RunCron(); err != nil { - return err + errs = append(errs, err) } } + + if len(errs) > 0 { + return fmt.Errorf("Encountered errors during cron process:\n%w", errors.Join(errs...)) + } return nil } diff --git a/internal/location.go b/internal/location.go index a20efa7..ce970ec 100644 --- a/internal/location.go +++ b/internal/location.go @@ -1,6 +1,7 @@ package internal import ( + "errors" "fmt" "io/ioutil" "os" @@ -446,7 +447,10 @@ func (l Location) RunCron() error { now := time.Now() if now.After(next) { lock.SetCron(l.name, now.Unix()) - l.Backup(true, "") + errs := l.Backup(true, "") + if len(errs) > 0 { + return fmt.Errorf("Failed to backup location \"%s\":\n%w", l.name, errors.Join(errs...)) + } } else { if !flags.CRON_LEAN { colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name)