diff --git a/pkg/util/steps/condition.go b/pkg/util/steps/condition.go index 3a6f8e8a517..9c27b580dd0 100644 --- a/pkg/util/steps/condition.go +++ b/pkg/util/steps/condition.go @@ -97,20 +97,20 @@ func (c conditionStep) run(ctx context.Context, log *logrus.Entry) error { return nil } if errors.Is(err, wait.ErrWaitTimeout) { - return enrichConditionTimeoutError(c.f) + return enrichConditionTimeoutError(c.f, err) } return err } // Instead of giving Generic, timed out waiting for a condition, error // returns enriched error messages mentioned in timeoutConditionErrors -func enrichConditionTimeoutError(f conditionFunction) error { +func enrichConditionTimeoutError(f conditionFunction, originalErr error) error { funcNameParts := strings.Split(FriendlyName(f), ".") funcName := strings.TrimSuffix(funcNameParts[len(funcNameParts)-1], "-fm") message, exists := timeoutConditionErrors[funcName] if !exists { - return errors.New("timed out waiting for the condition") + return originalErr } return api.NewCloudError( http.StatusInternalServerError, diff --git a/pkg/util/steps/condition_test.go b/pkg/util/steps/condition_test.go index cfecdaed7a1..973f9bb0977 100644 --- a/pkg/util/steps/condition_test.go +++ b/pkg/util/steps/condition_test.go @@ -5,6 +5,7 @@ package steps import ( "context" + "errors" "testing" ) @@ -23,17 +24,19 @@ func hiveClusterInstallationComplete(context.Context) (bool, error) { ret func TestEnrichConditionTimeoutError(t *testing.T) { for _, tt := range []struct { - desc string - function conditionFunction - wantErr string + desc string + function conditionFunction + originalErr string + wantErr string }{ // Verify response for func's mention in timeoutConditionErrors and // Emit generic Error if an unknown func { // unknown function - desc: "test conditionfail for func - unknownFunc", - function: timingOutCondition, - wantErr: "timed out waiting for the condition", + desc: "test conditionfail for func - unknownFunc", + function: timingOutCondition, + originalErr: "timed out waiting for the condition", + wantErr: "timed out waiting for the condition", }, { desc: "test conditionfail for func - apiServersReady", @@ -87,7 +90,7 @@ func TestEnrichConditionTimeoutError(t *testing.T) { }, } { t.Run(tt.desc, func(t *testing.T) { - if got := enrichConditionTimeoutError(tt.function); got.Error() != tt.wantErr { + if got := enrichConditionTimeoutError(tt.function, errors.New(tt.originalErr)); got.Error() != tt.wantErr { t.Errorf("invlaid enrichConditionTimeoutError: %s, got: %s", tt.wantErr, got) } })