Skip to content

Commit

Permalink
Reference IDs of share objects in share.go error messages.
Browse files Browse the repository at this point in the history
Without this, we get error messages like
```
Error: error reading share err = [errors.go:17] object does not exist or not authorized
```
that are nearly impossible to debug.
  • Loading branch information
originalrkk authored Dec 14, 2023
1 parent 6b852c2 commit 802f7ef
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/resources/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func CreateShare(d *schema.ResourceData, meta interface{}) error {
}
}
if err := client.Shares.Create(ctx, id, &opts); err != nil {
return fmt.Errorf("error creating share err = %w", err)
return fmt.Errorf("error creating share (%v) err = %w", d.Id(), err)
}
d.SetId(name)

Expand Down Expand Up @@ -127,22 +127,22 @@ func setShareAccounts(ctx context.Context, client *sdk.Client, shareID sdk.Accou
Database: tempDatabaseID,
}, shareID)
if err != nil {
return fmt.Errorf("error granting privilege to share err = %w", err)
return fmt.Errorf("error granting privilege to share (%v) err = %w", shareID.Name(), err)
}
defer func() {
// revoke the REFERENCE_USAGE privilege during cleanup
err = client.Grants.RevokePrivilegeFromShare(ctx, sdk.ObjectPrivilegeReferenceUsage, &sdk.RevokePrivilegeFromShareOn{
Database: tempDatabaseID,
}, shareID)
if err != nil {
log.Printf("[WARN] error revoking privilege from share err = %v", err)
log.Printf("[WARN] error revoking privilege from share (%v) err = %v", shareID.Name(), err)
}
// revoke the maybe automatically granted USAGE privilege during cleanup
err = client.Grants.RevokePrivilegeFromShare(ctx, sdk.ObjectPrivilegeUsage, &sdk.RevokePrivilegeFromShareOn{
Database: tempDatabaseID,
}, shareID)
if err != nil {
log.Printf("[WARN] error revoking privilege from share err = %v", err)
log.Printf("[WARN] error revoking privilege from share (%v) err = %v", shareID.Name(), err)
}
}()
// 3. Add accounts to the share
Expand All @@ -163,7 +163,7 @@ func ReadShare(d *schema.ResourceData, meta interface{}) error {

share, err := client.Shares.ShowByID(ctx, id)
if err != nil {
return fmt.Errorf("error reading share err = %w", err)
return fmt.Errorf("error reading share (%v) err = %w", d.Id(), err)
}
if err := d.Set("name", share.Name.Name()); err != nil {
return err
Expand Down Expand Up @@ -218,7 +218,7 @@ func UpdateShare(d *schema.ResourceData, meta interface{}) error {
},
})
if err != nil {
return fmt.Errorf("error removing accounts from share err = %w", err)
return fmt.Errorf("error removing accounts from share (%v) err = %w", d.Id(), err)
}
} else {
accountIdentifiers := accountIdentifiersFromSlice(newAccounts)
Expand All @@ -236,7 +236,7 @@ func UpdateShare(d *schema.ResourceData, meta interface{}) error {
},
})
if err != nil {
return fmt.Errorf("error updating share comment err = %w", err)
return fmt.Errorf("error updating share (%v) comment err = %w", d.Id(), err)
}
}

Expand All @@ -250,7 +250,7 @@ func DeleteShare(d *schema.ResourceData, meta interface{}) error {
ctx := context.Background()
err := client.Shares.Drop(ctx, sdk.NewAccountObjectIdentifier(d.Id()))
if err != nil {
return fmt.Errorf("error deleting share err = %w", err)
return fmt.Errorf("error deleting share (%v) err = %w", d.Id(), err)
}
return nil
}

0 comments on commit 802f7ef

Please sign in to comment.