Skip to content

Commit bf1fe89

Browse files
project_21597175_bot_e9036931e734db8fcf14172b2a96b4aaLMaxence
authored andcommitted
fix(cli): PRD-814 surface version check errors when verbose
Store GitHub release lookup failures, send a User-Agent on the request, and print the error with escape-cli version -v when the check fails. Co-authored-by: maxence <maxence@escape.tech>
1 parent d152360 commit bf1fe89

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

pkg/cli/cmd/version.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ and build date. Use this to verify your installation and check for updates.`,
2020
escape-cli version -o json`,
2121
Run: func(c *cobra.Command, _ []string) {
2222
v := version.GetDetailedVersion(c.Context())
23-
out.Print(v, v.String())
23+
text := v.String()
24+
if rootCmdVerbose > 0 && v.UpdateCheckError != "" {
25+
text += "\n Check error: " + v.UpdateCheckError
26+
}
27+
out.Print(v, text)
2428
},
2529
}
2630

pkg/version/update_check.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ type githubRelease struct {
2121

2222
// UpdateInfo stores the cached result of the latest release lookup.
2323
type UpdateInfo struct {
24-
Current string `json:"current,omitempty"`
25-
Latest string `json:"latest,omitempty"`
26-
Available bool `json:"available,omitempty"`
24+
Current string `json:"current,omitempty"`
25+
Latest string `json:"latest,omitempty"`
26+
Available bool `json:"available,omitempty"`
27+
CheckError string `json:"checkError,omitempty"`
2728
}
2829

2930
var (
@@ -66,6 +67,8 @@ func getLatestReleaseTag(ctx context.Context) (string, error) {
6667
if err != nil {
6768
return "", fmt.Errorf("create request: %w", err)
6869
}
70+
req.Header.Set("Accept", "application/vnd.github+json")
71+
req.Header.Set("User-Agent", "escape-cli/"+normalizeVersion(GetVersion().Version))
6972

7073
resp, err := client.Do(req)
7174
if err != nil {
@@ -101,7 +104,13 @@ func CheckForUpdate(parentCtx context.Context) *UpdateInfo {
101104
defer cancel()
102105

103106
latest, err := getLatestReleaseTag(ctx)
104-
if err != nil || latest == "" {
107+
if err != nil {
108+
info.CheckError = err.Error()
109+
updateInfo = info
110+
return
111+
}
112+
if latest == "" {
113+
info.CheckError = "empty latest release tag"
105114
updateInfo = info
106115
return
107116
}

pkg/version/version.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ type V struct {
2222
Commit string `json:"commit"`
2323
BuildDate string `json:"buildDate"`
2424
InstallMethod string `json:"installMethod,omitempty"`
25-
LatestVersion string `json:"latestVersion,omitempty"`
26-
UpgradeCommand string `json:"upgradeCommand,omitempty"`
25+
LatestVersion string `json:"latestVersion,omitempty"`
26+
UpgradeCommand string `json:"upgradeCommand,omitempty"`
27+
UpdateCheckError string `json:"updateCheckError,omitempty"`
2728
}
2829

2930
// GetVersion returns the version information
@@ -43,6 +44,7 @@ func GetDetailedVersion(ctx context.Context) V {
4344

4445
v.InstallMethod = string(installInfo.Method)
4546
v.LatestVersion = updateInfo.Latest
47+
v.UpdateCheckError = updateInfo.CheckError
4648
if updateInfo.Available {
4749
v.UpgradeCommand = UpgradeCommand(installInfo.Method, updateInfo.Latest)
4850
}

0 commit comments

Comments
 (0)