Skip to content

Commit

Permalink
improve the error message given when attempting to queue an invalid t…
Browse files Browse the repository at this point in the history
…est spec (#654)
  • Loading branch information
laverya authored Aug 7, 2024
1 parent fbce432 commit d32388d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tgrun/pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ func Run(schedulerOptions types.SchedulerOptions) error {
return errors.Wrap(err, "failed to read response body")
}

// attempt to unmarshal installerURL as a kurl error message - if this works, it's not a URL
var errMsg kurlErrResp
err = json.Unmarshal(installerURL, &errMsg)
if err == nil && errMsg.Error.Message != "" {
return fmt.Errorf("error getting kurl spec url for instance %s: %s", instance.Name, errMsg.Error.Message)
}

var upgradeYAML, upgradeURL []byte
if instance.UpgradeSpec != nil {
installer.Spec = *instance.UpgradeSpec
Expand Down Expand Up @@ -138,6 +145,12 @@ func Run(schedulerOptions types.SchedulerOptions) error {
return errors.Wrap(err, "failed to read upgrade response body")
}

// attempt to unmarshal upgradeURL as a kurl error message - if this works, it's not a URL
err = json.Unmarshal(upgradeURL, &errMsg)
if err == nil && errMsg.Error.Message != "" {
return fmt.Errorf("error getting kurl upgrade spec url for instance %s: %s", instance.Name, errMsg.Error.Message)
}

if instance.Airgap || schedulerOptions.Airgap {
upgradeURLString, err := getBundleFromURL(string(upgradeURL), schedulerOptions.KurlVersion)
if err != nil {
Expand All @@ -162,13 +175,6 @@ func Run(schedulerOptions types.SchedulerOptions) error {
}
}

// attempt to unmarshal installerURL as a kurl error message - if this works, it's not a URL
var errMsg kurlErrResp
err = json.Unmarshal(installerURL, &errMsg)
if err == nil && errMsg.Error.Message != "" {
return fmt.Errorf("error getting kurl spec url: %s", errMsg.Error.Message)
}

if instance.Airgap || schedulerOptions.Airgap {
installerURLString, err := getBundleFromURL(string(installerURL), schedulerOptions.KurlVersion)
if err != nil {
Expand Down

0 comments on commit d32388d

Please sign in to comment.