From 42500817e00eac293a3e2c4e9e818022d02c2b81 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 1 Sep 2018 10:36:22 +1000 Subject: [PATCH] better error for nonbackwards compatible changes --- pkg/i18n/english.go | 2 +- pkg/updates/updates.go | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index f6e865b7b..1d9e8b41e 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -329,7 +329,7 @@ func addEnglish(i18nObject *i18n.Bundle) error { Other: "You already have the latest version", }, &i18n.Message{ ID: "MajorVersionErr", - Other: "New version has non-backwards compatible changes.", + Other: "New version ({{.newVersion}}) has non-backwards compatible changes compared to the current version ({{.currentVersion}})", }, &i18n.Message{ ID: "CouldNotFindBinaryErr", Other: "Could not find any binary at {{.url}}", diff --git a/pkg/updates/updates.go b/pkg/updates/updates.go index 5f533e5a0..4ec374616 100644 --- a/pkg/updates/updates.go +++ b/pkg/updates/updates.go @@ -96,6 +96,7 @@ func (u *Updater) majorVersionDiffers(oldVersion, newVersion string) bool { func (u *Updater) checkForNewUpdate() (string, error) { u.Log.Info("Checking for an updated version") + currentVersion := u.Config.GetVersion() if err := u.RecordLastUpdateCheck(); err != nil { return "", err } @@ -104,15 +105,22 @@ func (u *Updater) checkForNewUpdate() (string, error) { if err != nil { return "", err } - u.Log.Info("Current version is " + u.Config.GetVersion()) + u.Log.Info("Current version is " + currentVersion) u.Log.Info("New version is " + newVersion) - if newVersion == u.Config.GetVersion() { + if newVersion == currentVersion { return "", errors.New(u.Tr.SLocalize("OnLatestVersionErr")) } - if u.majorVersionDiffers(u.Config.GetVersion(), newVersion) { - return "", errors.New(u.Tr.SLocalize("MajorVersionErr")) + if u.majorVersionDiffers(currentVersion, newVersion) { + errMessage := u.Tr.TemplateLocalize( + "MajorVersionErr", + i18n.Teml{ + "newVersion": newVersion, + "currentVersion": currentVersion, + }, + ) + return "", errors.New(errMessage) } rawUrl, err := u.getBinaryUrl(newVersion)