Skip to content

Commit ea8270d

Browse files
authored
feat: improve 'missing license'/'mismatched license' error messages (#400)
* improve 'missing license'/'mismatched license' error messages * add to suggested node reset command * add sudo to suggested node reset command * make consistent
1 parent 68d9341 commit ea8270d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

cmd/embedded-cluster/install.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,26 @@ func checkLicenseMatches(c *cli.Context) error {
133133
return nil
134134
} else if rel == nil && c.String("license") != "" {
135135
// license is present but no release, this means we would install without vendor charts and k0s overrides
136-
return fmt.Errorf("a license was provided but no release was found in binary")
136+
return fmt.Errorf("a license was provided but no release was found in binary, please rerun without the license flag")
137137
} else if rel != nil && c.String("license") == "" {
138138
// release is present but no license, this is not OK
139-
return fmt.Errorf("no license was provided for %s", rel.AppSlug)
139+
return fmt.Errorf("no license was provided for %s and one is required, please rerun with '--license <path to license file>'", rel.AppSlug)
140140
}
141141

142142
license, err := helpers.ParseLicense(c.String("license"))
143143
if err != nil {
144-
return fmt.Errorf("unable to parse license: %w", err)
144+
return fmt.Errorf("unable to parse the license file at %q, please ensure it is not corrupt: %w", c.String("license"), err)
145145
}
146146

147147
// Check if the license matches the application version data
148148
if rel.AppSlug != license.Spec.AppSlug {
149149
// if the app is different, we will not be able to provide the correct vendor supplied charts and k0s overrides
150-
return fmt.Errorf("license app %s does not match binary app %s", license.Spec.AppSlug, rel.AppSlug)
150+
return fmt.Errorf("license app %s does not match binary app %s, please provide the correct license", license.Spec.AppSlug, rel.AppSlug)
151151
}
152152
if rel.ChannelID != license.Spec.ChannelID {
153153
// if the channel is different, we will not be able to install the pinned vendor application version within kots
154154
// this may result in an immediate k8s upgrade after installation, which is undesired
155-
return fmt.Errorf("license channel %s (%s) does not match binary channel %s", license.Spec.ChannelID, license.Spec.ChannelName, rel.ChannelID)
155+
return fmt.Errorf("license channel %s (%s) does not match binary channel %s, please provide the correct license", license.Spec.ChannelID, license.Spec.ChannelName, rel.ChannelID)
156156
}
157157

158158
return nil
@@ -333,15 +333,15 @@ var installCommand = &cli.Command{
333333
logrus.Errorf("An installation has been detected on this machine.")
334334
logrus.Infof("If you want to reinstall you need to remove the existing installation")
335335
logrus.Infof("first. You can do this by running the following command:")
336-
logrus.Infof("\n %s node reset\n", defaults.BinaryName())
336+
logrus.Infof("\n sudo ./%s node reset\n", defaults.BinaryName())
337337
return ErrNothingElseToAdd
338338
}
339339
metrics.ReportApplyStarted(c)
340340
logrus.Debugf("checking license matches")
341341
if err := checkLicenseMatches(c); err != nil {
342-
err := fmt.Errorf("unable to check license: %w", err)
343-
metrics.ReportApplyFinished(c, err)
344-
return err
342+
metricErr := fmt.Errorf("unable to check license: %w", err)
343+
metrics.ReportApplyFinished(c, metricErr)
344+
return err // do not return the metricErr, as we want the user to see the error message without a prefix
345345
}
346346
logrus.Debugf("materializing binaries")
347347
if err := goods.Materialize(); err != nil {

0 commit comments

Comments
 (0)