Handle 0 size data files and augment the error that comes back from Unmarshal
This commit is contained in:
parent
20f50b678c
commit
b9d5a54741
1 changed files with 3 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue