From 6c68e303378faac09db2b27d260a5bbca1c3ebd5 Mon Sep 17 00:00:00 2001 From: Diegiwg Date: Wed, 26 Jun 2024 09:29:54 -0300 Subject: [PATCH] fix: handle corrupted database file properly --- .version | 2 +- data/load.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.version b/.version index 8b3a022..23c38c2 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -v1.3.0 \ No newline at end of file +v1.3.1 \ No newline at end of file diff --git a/data/load.go b/data/load.go index 3258d66..da3a58b 100644 --- a/data/load.go +++ b/data/load.go @@ -29,7 +29,12 @@ func ReadOrCreateRecord(ctx *cli.Context) model.RecordTable { err = json.Unmarshal(fileContent, &table) if err != nil { - panic(err) + println("Database file is corrupted. Creating new one.") + + table = model.NewRecordTable() + table.Add(model.NewRecord()) + + SaveRecordToFile(ctx, &table) } return table