diff --git a/cmd/restray/cli.go b/cmd/restray/cli.go index da35939..3a322dd 100644 --- a/cmd/restray/cli.go +++ b/cmd/restray/cli.go @@ -281,6 +281,9 @@ func cliMount(prof Profile) error { } func cliSchedule(prof Profile) error { + if errMsg := prof.profileError(); errMsg != "" { + return cli.Exit("error: "+errMsg, 1) + } p, _ := findBackend(prof) if p == "" { return cli.Exit("error: "+prof.backendName()+" not found", 1) @@ -365,7 +368,7 @@ func buildDaemonSchedule() (*cron.Cron, error) { } key := prof.profileKey() name := prof.displayName() - if errMsg := prof.scheduleError(); errMsg != "" { + if errMsg := prof.scheduleConfigError(); errMsg != "" { log.Printf("[%s] skipping schedule: %s", name, errMsg) continue } diff --git a/cmd/restray/config.go b/cmd/restray/config.go index 5c8ae21..0014c14 100644 --- a/cmd/restray/config.go +++ b/cmd/restray/config.go @@ -133,31 +133,32 @@ func parseEnvFile(path string) (map[string]string, error) { return env, nil } -func (prof Profile) scheduleError() string { - vars, err := parseEnvFile(prof.EnvFile) - if err != nil { - return "Env file not found" - } +func (prof Profile) scheduleConfigError() string { if prof.backend() == "" { return "Unsupported backend: " + prof.Backend } - if err := backendEnvError(prof.backend(), vars); err != "" { - return err - } if prof.Schedule.BackupEnabled() && len(prof.Backup.Paths) == 0 { return "No paths configured" } return "" } -func (prof Profile) configError() string { - if err := prof.scheduleError(); err != "" { +func (prof Profile) environmentError() string { + vars, err := parseEnvFile(prof.EnvFile) + if err != nil { + return "Env file not available" + } + return backendEnvError(prof.backend(), vars) +} + +func (prof Profile) profileError() string { + if err := prof.scheduleConfigError(); err != "" { return err } if len(prof.Backup.Paths) == 0 { return "No paths configured" } - return "" + return prof.environmentError() } func (prof Profile) displayName() string { diff --git a/cmd/restray/operations.go b/cmd/restray/operations.go index 7f702b9..44e6d76 100644 --- a/cmd/restray/operations.go +++ b/cmd/restray/operations.go @@ -354,6 +354,12 @@ func runScheduled(key stateKey, mStatus prefixedMenuItem, prof Profile, onDone f setProfileFailed(key, "") defer onDone() defer releaseProfile(key) + if errMsg := prof.profileError(); errMsg != "" { + mStatus.SetTitle(errMsg) + setProfileFailed(key, errMsg) + notifyError("Schedule", errMsg) + return + } hookEnv := []string{ "RESTRAY_OPERATIONS=" + strings.Join(scheduledOpNames(prof), ","), diff --git a/cmd/restray/tray.go b/cmd/restray/tray.go index bf4179e..338bf33 100644 --- a/cmd/restray/tray.go +++ b/cmd/restray/tray.go @@ -531,7 +531,7 @@ func onReady() { ps.errMsg = prof.backendDisplayName() + " not found" return ps } - ps.errMsg = prof.configError() + ps.errMsg = prof.profileError() if ps.errMsg == "" { wantsLast := cfg.GUI.ScheduleDisplay == "last" && getLastBackup(prof.profileKey()).IsZero() var rs repoResult @@ -704,7 +704,7 @@ func onReady() { ps := probeProfileState(cfg, i, prof) if prof.Schedule.Cron != "" && i < maxProfiles { - if errMsg := prof.scheduleError(); errMsg != "" { + if errMsg := prof.scheduleConfigError(); errMsg != "" { log.Printf("[%s] skipping schedule: %s", prof.displayName(), errMsg) } else { key := prof.profileKey()