Skip to content

Commit

Permalink
Avoid panic even if state file is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
babarot committed Mar 24, 2022
1 parent b75e39b commit 3903828
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var ReadStateFile = func(filename string) ([]byte, error) {
f, err := os.Open(filename)
if err != nil {
// return empty json contents if state.json does not exist
return []byte(`{}`), nil
return []byte(`{"resources":{}}`), nil
}
defer f.Close()

Expand Down Expand Up @@ -244,6 +244,7 @@ func Keys(resources []Resource) []string {

func Open(path string, resourcers []Resourcer) (*State, error) {
s := State{
Self: Self{Resources: map[ID]Resource{}},
path: path,
packages: map[ID]Resource{},
mu: sync.RWMutex{},
Expand Down

0 comments on commit 3903828

Please sign in to comment.