Handle 0 size data files and augment the error that comes back from Unmarshal

This commit is contained in:
Marc Di Luzio 2020-06-03 12:58:10 +01:00
parent 20f50b678c
commit b9d5a54741

View file

@ -52,8 +52,10 @@ func Load(name string, data interface{}) error {
// Read and unmarshal the json
if b, err := ioutil.ReadFile(path); err != nil {
return err
} else if len(b) == 0 {
fmt.Printf("File %s was empty, loading with fresh data\n", path)
} else if err := json.Unmarshal(b, data); err != nil {
return err
return fmt.Errorf("failed to load file %s error: %s", path, err)
}
return nil
}