Skip to content

Commit

Permalink
[store] if store.json is empty, don't try to unmarshal it (#177)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ryantm authored Dec 12, 2023
1 parent f0bea07 commit d8ad57a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"os"
"path/filepath"
"strings"

"github.com/replit/upm/internal/api"
"github.com/replit/upm/internal/util"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d8ad57a

Please sign in to comment.