signer/core: handle JSON unmarshal error (#19123)

This commit is contained in:
Hsien-Tang Kao 2019-02-19 00:48:19 -08:00 committed by Péter Szilágyi
parent 4a090a1bab
commit c283d9b5e8

View File

@ -177,7 +177,9 @@ func NewAbiDBFromFile(path string) (*AbiDb, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
json.Unmarshal(raw, &db.db) if err := json.Unmarshal(raw, &db.db); err != nil {
return nil, err
}
return db, nil return db, nil
} }
@ -192,14 +194,18 @@ func NewAbiDBFromFiles(standard, custom string) (*AbiDb, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
json.Unmarshal(raw, &db.db) if err := json.Unmarshal(raw, &db.db); err != nil {
return nil, err
}
// Custom file may not exist. Will be created during save, if needed // Custom file may not exist. Will be created during save, if needed
if _, err := os.Stat(custom); err == nil { if _, err := os.Stat(custom); err == nil {
raw, err = ioutil.ReadFile(custom) raw, err = ioutil.ReadFile(custom)
if err != nil { if err != nil {
return nil, err return nil, err
} }
json.Unmarshal(raw, &db.customdb) if err := json.Unmarshal(raw, &db.customdb); err != nil {
return nil, err
}
} }
return db, nil return db, nil