don't crash when config is empty

Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
Hadi
2026-04-10 23:38:08 +02:00
parent 63e71f42cf
commit 3b75d945c4

View File

@@ -2,6 +2,7 @@ package config
import ( import (
"fmt" "fmt"
"io"
"log" "log"
"os" "os"
@@ -86,6 +87,10 @@ func Load(path string) (*Config, error) {
dec := yaml.NewDecoder(f) dec := yaml.NewDecoder(f)
dec.KnownFields(true) dec.KnownFields(true)
if err := dec.Decode(&cfg); err != nil { if err := dec.Decode(&cfg); err != nil {
if err == io.EOF {
log.Printf("config: %q is empty, starting with empty config", path)
return Default(), nil
}
return nil, fmt.Errorf("config: decode: %w", err) return nil, fmt.Errorf("config: decode: %w", err)
} }
return &cfg, nil return &cfg, nil