Skip to content

Commit

Permalink
handling empty file before unmarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
so-sahu committed Feb 8, 2024
1 parent c000818 commit cf813ce
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/host/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ func (s *Store[E]) get(id string) (E, error) {
}

obj := s.newFunc()
if len(file) == 0 {
return obj, err
}

if err := json.Unmarshal(file, &obj); err != nil {
return utils.Zero[E](), fmt.Errorf("failed to unmarshal object: %w", err)
}
Expand Down

0 comments on commit cf813ce

Please sign in to comment.