From d8ad57a2f74e8ce7811b93a3fe3474ada8d6686c Mon Sep 17 00:00:00 2001 From: Ryan Mulligan Date: Tue, 12 Dec 2023 07:47:28 -0800 Subject: [PATCH] [store] if store.json is empty, don't try to unmarshal it (#177) Why === * We're seeing many error logs with > store.json: unexpected end of JSON input * Looking at the Repls, it appears they have an empty store.json file What changed === * If the store.json file is empty or only whitespace, skip unmarshalling and assume it is empty Test plan === * ran `UPM_STORE=store.json ./result/bin/upm -l nodejs add express` with an empty store.json file before and after the change --- internal/store/store.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/store/store.go b/internal/store/store.go index e00e96b7..fea0a0b2 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -8,6 +8,7 @@ import ( "encoding/json" "os" "path/filepath" + "strings" "github.com/replit/upm/internal/api" "github.com/replit/upm/internal/util" @@ -50,8 +51,10 @@ func read() { util.Die("%s: %s", filename, err) } - if err = json.Unmarshal(bytes, st); err != nil { - util.Die("%s: %s", filename, err) + if len(strings.TrimSpace(string(bytes))) > 0 { + if err = json.Unmarshal(bytes, st); err != nil { + util.Die("%s: %s", filename, err) + } } if st.Version != currentVersion {