Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handling timeouts with proper error messages #924

Merged
merged 7 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/provider/resource_subaccount_environment_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func (rs *subaccountEnvironmentInstanceResource) Create(ctx context.Context, req
updatedRes, err := createStateConf.WaitForStateContext(ctx)
if err != nil {
resp.Diagnostics.AddError("API Error Creating Resource Environment Instance (Subaccount)", fmt.Sprintf("%s", err))
return
}

plan, diags = subaccountEnvironmentInstanceValueFrom(ctx, updatedRes.(provisioning.EnvironmentInstanceResponseObject))
Expand Down Expand Up @@ -339,6 +340,7 @@ func (rs *subaccountEnvironmentInstanceResource) Update(ctx context.Context, req
updatedRes, err := updateStateConf.WaitForStateContext(ctx)
if err != nil {
resp.Diagnostics.AddError("API Error Updating Resource Environment Instance (Subaccount)", fmt.Sprintf("%s", err))
return
}

state, diags := subaccountEnvironmentInstanceValueFrom(ctx, updatedRes.(provisioning.EnvironmentInstanceResponseObject))
Expand Down
6 changes: 5 additions & 1 deletion internal/provider/resource_subaccount_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ func (rs *subaccountSubscriptionResource) Create(ctx context.Context, req resour
resp.Diagnostics.AddError("API Error Creating Resource Subscription (Subaccount)", fmt.Sprintf("%s", err))
}

if updatedRes == nil {
lechnerc77 marked this conversation as resolved.
Show resolved Hide resolved
return
}

updatedPlan, diags := subaccountSubscriptionValueFrom(ctx, updatedRes.(saas_manager_service.EntitledApplicationsResponseObject))
updatedPlan.Parameters = plan.Parameters
updatedPlan.Timeouts = plan.Timeouts
Expand Down Expand Up @@ -316,7 +320,7 @@ func (rs *subaccountSubscriptionResource) CreateStateChange(ctx context.Context,

timeoutsLocal := plan.Timeouts

createTimeout, diags := timeoutsLocal.Update(ctx, tfutils.DefaultTimeout)
createTimeout, diags := timeoutsLocal.Create(ctx, tfutils.DefaultTimeout)
summary.Append(diags...)
delay, minTimeout := tfutils.CalculateDelayAndMinTimeOut(createTimeout)

Expand Down
2 changes: 1 addition & 1 deletion internal/tfutils/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (e *TimeoutError) Error() string {
expectedState, suffix, e.LastError)
}

return fmt.Sprintf("timeout while waiting for %s%s",
return fmt.Sprintf("timeout while waiting for %s%s\ntry increasing the timeout for this particular operation",
expectedState, suffix)
}

Expand Down
6 changes: 3 additions & 3 deletions internal/tfutils/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestWaitForState_timeout(t *testing.T) {
t.Fatal("Expected timeout error. No error returned.")
}

expectedErr := "timeout while waiting for state to become 'running' (timeout: 1ms)"
expectedErr := "timeout while waiting for state to become 'running' (timeout: 1ms)\ntry increasing the timeout for this particular operation"
if err.Error() != expectedErr {
t.Fatalf("Errors don't match.\nExpected: %q\nGiven: %q\n", expectedErr, err.Error())
}
Expand Down Expand Up @@ -235,7 +235,7 @@ func TestWaitForState_cancel(t *testing.T) {
t.Fatal("Expected timeout error. No error returned.")
}

expectedErr := "timeout while waiting for state to become 'running'"
expectedErr := "timeout while waiting for state to become 'running' (last state: 'pending', timeout: 10ms)\ntry increasing the timeout for this particular operation"
if !strings.HasPrefix(err.Error(), expectedErr) {
t.Fatalf("Errors don't match.\nExpected: %q\nGiven: %q\n", expectedErr, err.Error())
}
Expand Down Expand Up @@ -322,7 +322,7 @@ func TestWaitForState_failureEmpty(t *testing.T) {
if err == nil {
t.Fatal("Expected timeout error. Got none.")
}
expectedErr := "timeout while waiting for resource to be gone (last state: 'pending', timeout: 100ms)"
expectedErr := "timeout while waiting for resource to be gone (last state: 'pending', timeout: 100ms)\ntry increasing the timeout for this particular operation"
if err.Error() != expectedErr {
t.Fatalf("Errors don't match.\nExpected: %q\nGiven: %q\n", expectedErr, err.Error())
}
Expand Down