Skip to content

Commit

Permalink
fix: uninitialized values map
Browse files Browse the repository at this point in the history
  • Loading branch information
siddarthkay committed Jun 30, 2024
1 parent b4295df commit b6283d9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pairing_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,27 @@ type pairingStore struct {
}

func newPairingStore(storage string) (*pairingStore, error) {
p := &pairingStore{path: storage}
b, err := os.ReadFile(p.path)
p := &pairingStore{
path: storage,
values: make(map[string]*PairingInfo),
}

b, err := os.ReadFile(p.path)
if err != nil {
if os.IsNotExist(err) {
parent := filepath.Dir(p.path)
err = os.MkdirAll(parent, 0750)

if err != nil {
return nil, err
}

p.values = map[string]*PairingInfo{}
} else {
return nil, err
}
} else {
err = json.Unmarshal(b, &p.values)

if err != nil {
p.values = make(map[string]*PairingInfo)
l("error at newPairingStore is %+v", err)
return nil, err
}
}
Expand Down

0 comments on commit b6283d9

Please sign in to comment.