Skip to content

Commit

Permalink
Add additional information to the retry errors
Browse files Browse the repository at this point in the history
References: #3016
  • Loading branch information
sfc-gh-asawicki committed Sep 5, 2024
1 parent 036bcb7 commit 4d20686
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/resources/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resources
import (
"context"
"fmt"
"log"
"strings"
"time"

Expand Down Expand Up @@ -299,6 +300,7 @@ func CreateAccount(d *schema.ResourceData, meta interface{}) error {
err = util.Retry(5, 3*time.Second, func() (error, bool) {
account, err = client.Accounts.ShowByID(ctx, objectIdentifier)
if err != nil {
log.Printf("[DEBUG] retryable operation resulted in error: %v\n", err)
return nil, false
}
return nil, true
Expand All @@ -323,6 +325,7 @@ func ReadAccount(d *schema.ResourceData, meta interface{}) error {
err = util.Retry(5, 3*time.Second, func() (error, bool) {
acc, err = client.Accounts.ShowByID(ctx, id)
if err != nil {
log.Printf("[DEBUG] retryable operation resulted in error: %v\n", err)
return nil, false
}
return nil, true
Expand Down
2 changes: 2 additions & 0 deletions pkg/resources/managed_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resources
import (
"context"
"fmt"
"log"
"time"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/helpers"
Expand Down Expand Up @@ -137,6 +138,7 @@ func ReadManagedAccount(d *schema.ResourceData, meta interface{}) error {
err = util.Retry(5, 3*time.Second, func() (error, bool) {
managedAccount, err = client.ManagedAccounts.ShowByID(ctx, id)
if err != nil {
log.Printf("[DEBUG] retryable operation resulted in error: %v\n", err)
return nil, false
}
return nil, true
Expand Down
9 changes: 7 additions & 2 deletions pkg/sdk/warehouses.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,20 @@ func (c *warehouses) Alter(ctx context.Context, id AccountObjectIdentifier, opts
}()

// needed to make sure that warehouse is suspended
var warehouseSuspensionErrs []error
err = util.Retry(3, 1*time.Second, func() (error, bool) {
warehouse, err = c.ShowByID(ctx, id)
if err != nil || warehouse.State != WarehouseStateSuspended {
if err != nil {
warehouseSuspensionErrs = append(warehouseSuspensionErrs, err)
return nil, false
}
if warehouse.State != WarehouseStateSuspended {
return nil, false
}
return nil, true
})
if err != nil {
return err
return fmt.Errorf("warehouse suspension failed, err: %w, original errors: %s", err, errors.Join(warehouseSuspensionErrs...))
}
}
}
Expand Down

0 comments on commit 4d20686

Please sign in to comment.