diff --git a/cmd/gpu-turnstile/main.go b/cmd/gpu-turnstile/main.go index 85ad834..393b660 100644 --- a/cmd/gpu-turnstile/main.go +++ b/cmd/gpu-turnstile/main.go @@ -299,6 +299,9 @@ func forceUpdateCommand(configPath string, elevatedChild bool) int { defer waitForEnter() } cfg, err := loadMergedConfig(configPath) + if errors.Is(err, config.ErrNoConsumer) { + err = nil // update settings do not depend on a consumer URL + } if err != nil { fmt.Fprintf(os.Stderr, "%s\n\ngpu-turnstile: %v\n", versionLine(), err) return 1 diff --git a/internal/config/config.go b/internal/config/config.go index d5efa85..1cb0f52 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -4,6 +4,7 @@ package config import ( "bufio" + "errors" "fmt" "io" "log/slog" @@ -84,6 +85,11 @@ func Defaults() Config { } } +// ErrNoConsumer is returned by Load when neither OLLAMA_URL nor COMFY_URL +// is set. Commands that never talk to an upstream (--force-update) may +// ignore it and proceed with the rest of the configuration. +var ErrNoConsumer = errors.New("at least one of OLLAMA_URL or COMFY_URL must be set (each URL enables its consumer)") + // ParseEnvFile parses a .env-style file: KEY=VALUE lines, blank lines and // #-comments are ignored, no quoting. A line without '=' is an error. func ParseEnvFile(r io.Reader) (map[string]string, error) { @@ -219,7 +225,7 @@ func Load(getenv func(string) string) (Config, error) { return cfg, fmt.Errorf("LOG_FORMAT: must be \"text\" or \"json\"") } if cfg.OllamaURL == "" && cfg.ComfyURL == "" { - return cfg, fmt.Errorf("at least one of OLLAMA_URL or COMFY_URL must be set (each URL enables its consumer)") + return cfg, ErrNoConsumer } return cfg, nil } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 17411cd..0b21cba 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -1,6 +1,7 @@ package config import ( + "errors" "log/slog" "strings" "testing" @@ -39,6 +40,9 @@ func TestLoadRequiresConsumer(t *testing.T) { if err == nil || !strings.Contains(err.Error(), "OLLAMA_URL") { t.Fatalf("err = %v, want missing-consumer error", err) } + if !errors.Is(err, ErrNoConsumer) { + t.Fatalf("err = %v, want errors.Is(err, ErrNoConsumer)", err) + } } func TestParseEnvFile(t *testing.T) {