Skip to content

Commit

Permalink
fix: error reading empty events.json
Browse files Browse the repository at this point in the history
  • Loading branch information
sumanchapai committed Mar 4, 2024
1 parent 51ab63c commit 10ba623
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func PrintKnockEvents(events []KnockEvent) {
func eventsFromEventsFile() []Event {
configFolder := ereConfigFolder()
eventsFile := filepath.Join(configFolder, ereEventsFileName)
_, err := os.Stat(eventsFile)
events := make([]Event, 0)
_, err := os.Stat(eventsFile)
if errors.Is(err, os.ErrNotExist) {
_, err := os.Create(eventsFile)
if err != nil {
Expand All @@ -139,6 +139,9 @@ func eventsFromEventsFile() []Event {
log.Fatal(err)
}
bytes, err := io.ReadAll(jsonFile)
if len(bytes) == 0 {
return events
}
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 10ba623

Please sign in to comment.