Skip to content

Commit

Permalink
Re-export internal SDK error and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed May 7, 2024
1 parent 64f4beb commit 4501e72
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
3 changes: 1 addition & 2 deletions pkg/resources/grant_privileges_to_account_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,7 @@ func ReadGrantPrivilegesToAccountRole(ctx context.Context, d *schema.ResourceDat

client := meta.(*provider.Context).Client

// TODO(SNOW-891217): Use custom error. Right now, "object does not exist" error is hidden in sdk/internal/collections package
if _, err := client.Roles.ShowByID(ctx, id.RoleName); err != nil && err.Error() == "object does not exist" {
if _, err := client.Roles.ShowByID(ctx, id.RoleName); err != nil && errors.Is(err, sdk.ErrObjectNotFound) {
d.SetId("")
return diag.Diagnostics{
diag.Diagnostic{
Expand Down
3 changes: 1 addition & 2 deletions pkg/resources/grant_privileges_to_database_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,7 @@ func ReadGrantPrivilegesToDatabaseRole(ctx context.Context, d *schema.ResourceDa
}

client := meta.(*provider.Context).Client
// TODO(SNOW-891217): Use custom error. Right now, "object does not exist" error is hidden in sdk/internal/collections package
if _, err := client.DatabaseRoles.ShowByID(ctx, id.DatabaseRoleName); err != nil && err.Error() == "object does not exist" {
if _, err := client.DatabaseRoles.ShowByID(ctx, id.DatabaseRoleName); err != nil && errors.Is(err, sdk.ErrObjectNotFound) {
d.SetId("")
return diag.Diagnostics{
diag.Diagnostic{
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/grant_privileges_to_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ func setRolePrivilegeOptions(privileges []string, allPrivileges bool, onAccount
}

func readRoleGrantPrivileges(ctx context.Context, client *sdk.Client, grantedOn sdk.ObjectType, id GrantPrivilegesToRoleID, opts *sdk.ShowGrantOptions, d *schema.ResourceData) error {
if _, err := client.Roles.ShowByID(ctx, sdk.NewAccountObjectIdentifier(id.RoleName)); err != nil && err.Error() == "object does not exist" {
if _, err := client.Roles.ShowByID(ctx, sdk.NewAccountObjectIdentifier(id.RoleName)); err != nil && errors.Is(err, sdk.ErrObjectNotFound) {
d.SetId("")
log.Printf("[DEBUG] Failed to retrieve account role. Marking the resource as removed.")
return nil
Expand Down
3 changes: 2 additions & 1 deletion pkg/resources/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"
"errors"
"fmt"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/provider"
Expand Down Expand Up @@ -77,7 +78,7 @@ func ReadAccountRole(ctx context.Context, d *schema.ResourceData, meta any) diag

accountRole, err := client.Roles.ShowByID(ctx, id)
if err != nil {
if err.Error() == "object does not exist" {
if errors.Is(err, sdk.ErrObjectNotFound) {
d.SetId("")
return diag.Diagnostics{
diag.Diagnostic{
Expand Down
4 changes: 4 additions & 0 deletions pkg/sdk/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sdk
import (
"errors"
"fmt"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections"

Check failure on line 6 in pkg/sdk/errors.go

View workflow job for this annotation

GitHub Actions / reviewdog

[golangci] reported by reviewdog 🐶 File is not `gofumpt`-ed (gofumpt) Raw Output: pkg/sdk/errors.go:6: File is not `gofumpt`-ed (gofumpt) "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/internal/collections"
"log"
"regexp"
"runtime"
Expand All @@ -13,6 +14,9 @@ var (
ErrNilOptions = NewError("options cannot be nil")
ErrPatternRequiredForLikeKeyword = NewError("pattern must be specified for like keyword")

// re-importing from internal package
ErrObjectNotFound = collections.ErrObjectNotFound

// go-snowflake errors.
ErrObjectNotExistOrAuthorized = NewError("object does not exist or not authorized")
ErrAccountIsEmpty = NewError("account is empty")
Expand Down

0 comments on commit 4501e72

Please sign in to comment.