From e77348d9a4a0c91cc0a66943e0ab392deaed6045 Mon Sep 17 00:00:00 2001 From: Tyagiquamar Date: Fri, 4 Sep 2026 23:52:18 +0530 Subject: [PATCH] fix(common): add nil safety and normalize version comparison in CheckVersionUpdate --- common/common.go | 14 ++++++++------ common/common_test.go | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/common/common.go b/common/common.go index e07fa0357..155331a0b 100644 --- a/common/common.go +++ b/common/common.go @@ -3,6 +3,7 @@ package common import ( "context" "fmt" + "strings" "github.com/google/go-github/v57/github" "github.com/savioxavier/termlink" @@ -45,15 +46,16 @@ func GithubClient() *github.Client { func CheckVersionUpdate() { ghClient := GithubClient() res, skip := VersionCheck(ghClient) - if skip { + if skip || res == nil || res.TagName == nil { return } - // Check if the version is different from the one in the binary - if res.TagName != nil && *res.TagName != fmt.Sprintf("v%s", VersionCli) { - if res.TagName != nil && *res.TagName != VersionCli { - fmt.Printf("A newer version (%s) is available, please upgrade with \"civo update\"\n", *res.TagName) - } + latest := *res.TagName + latestClean := strings.TrimPrefix(latest, "v") + currentClean := strings.TrimPrefix(VersionCli, "v") + + if latestClean != currentClean { + fmt.Printf("A newer version (%s) is available, please upgrade with \"civo update\"\n", latest) } } diff --git a/common/common_test.go b/common/common_test.go index e55725b39..0e75ad703 100644 --- a/common/common_test.go +++ b/common/common_test.go @@ -32,3 +32,19 @@ func TestVersionCheck(t *testing.T) { } }) } + +func TestCheckVersionUpdate(t *testing.T) { + t.Run("nil release or tag safety", func(t *testing.T) { + oldCli := VersionCli + defer func() { VersionCli = oldCli }() + + VersionCli = "1.0.0" + + // Ensure calling with nil handling doesn't panic + res, skip := VersionCheck(github.NewClient(nil)) + if skip && res == nil { + // Should return cleanly without panic + CheckVersionUpdate() + } + }) +}