Skip to content

Commit

Permalink
internal/update: don't error with no build version
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Layher <mdlayher@planetscale.com>
  • Loading branch information
mdlayher committed Dec 22, 2023
1 parent 90e87e0 commit 96492a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func Execute(ctx context.Context, ver, commit, buildDate string) int {
case ui := <-updateCheckRes:
ui.PrintUpdateHint(ver)
case err := <-updateCheckErr:
fmt.Fprintf(os.Stderr, "Updater error: %#v\n", err)
fmt.Fprintf(os.Stderr, "Updater error: %v\n", err)
case <-updateTimeout:
}
}()
Expand Down
10 changes: 10 additions & 0 deletions internal/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ func checkVersion(

v2, err := version.NewVersion(buildVersion)
if err != nil {
if buildVersion == "" {
// A self-compiled binary has no version and thus parsing the
// version fails.
return &UpdateInfo{
Update: false,
Reason: fmt.Sprintf("Binary has no build version, cannot compare against latest version (%s)", info.Version),
ReleaseInfo: info,
}, nil
}

return nil, err
}

Expand Down
10 changes: 10 additions & 0 deletions internal/update/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ func TestCheckVersion(t *testing.T) {
update bool
lastChecked time.Time
}{
{
name: "self-compiled",
buildVersion: "",
latestVersion: "v0.2.0",
update: false,
},
{
name: "new version",
buildVersion: "v0.1.0",
Expand Down Expand Up @@ -112,6 +118,10 @@ func TestCheckVersion(t *testing.T) {

c.Assert(err, qt.IsNil)
c.Assert(updateInfo.Update, qt.Equals, tt.update, qt.Commentf("reason: %s", updateInfo.Reason))

if !tt.update {
t.Logf("reason: %s", updateInfo.Reason)
}
})
}
}

0 comments on commit 96492a1

Please sign in to comment.