config: improve error message for outdated CLIs

This commit is contained in:
Otto Bittner 2023-02-15 10:18:49 +01:00
parent e600795239
commit 2a0b56f7b8
2 changed files with 7 additions and 3 deletions

View File

@ -22,9 +22,11 @@ var (
// ErrMajorMismatch signals that the major version of two compared versions don't match.
ErrMajorMismatch = errors.New("missmatching major version")
// ErrMinorDrift signals that the minor version of two compared versions are further apart than one.
ErrMinorDrift = errors.New("target version needs to be equal or up to one minor version higher")
ErrMinorDrift = errors.New("version difference larger than one minor version")
// ErrSemVer signals that a given version does not adhere to the Semver syntax.
ErrSemVer = errors.New("invalid semantic version")
// ErrOutdatedCLI signals that the configured version is newer than the CLI. This is not allowed.
ErrOutdatedCLI = errors.New("target version newer than cli version")
)
// EnsurePrefixV returns the input string prefixed with the letter "v", if the string doesn't already start with that letter.
@ -89,7 +91,7 @@ func BinaryWith(target string) error {
return ErrMajorMismatch
}
if semver.Compare(binaryVersion, target) == -1 {
return ErrMinorDrift
return ErrOutdatedCLI
}
// Abort if minor version drift between CLI and versionA value is greater than 1.
if cliMinor-targetMinor > 1 {

View File

@ -328,7 +328,9 @@ func translateVersionCompatibilityError(ut ut.Translator, fe validator.FieldErro
case errors.Is(err, compatibility.ErrMajorMismatch):
msg = fmt.Sprintf("the CLI's major version (%s) has to match your configured major version (%s)", constants.VersionInfo, fe.Value().(string))
case errors.Is(err, compatibility.ErrMinorDrift):
msg = fmt.Sprintf("only the CLI (%s) can be up to one minor version newer than the configured version (%s)", constants.VersionInfo, fe.Value().(string))
msg = fmt.Sprintf("the CLI's minor version (%s) and the configured version (%s) are more than one minor version apart", constants.VersionInfo, fe.Value().(string))
case errors.Is(err, compatibility.ErrOutdatedCLI):
msg = fmt.Sprintf("the CLI's version (%s) is older than the configured version (%s)", constants.VersionInfo, fe.Value().(string))
default:
msg = err.Error()
}