mirror of
https://github.com/anotherhadi/iknowyou.git
synced 2026-04-11 16:37:25 +02:00
don't crash when config is empty
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user