Skip to content

Commit

Permalink
materialize-snowflake: better error message for table creation access…
Browse files Browse the repository at this point in the history
… issue

Provide a better error message if the user does not have permission to create a
table in the selected schema.
  • Loading branch information
williamhbaker committed Oct 1, 2024
1 parent 23bf5e9 commit 5f38d5c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions materialize-snowflake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
stdsql "database/sql"
"errors"
"fmt"
"regexp"
"strings"

boilerplate "github.com/estuary/connectors/materialize-boilerplate"
Expand Down Expand Up @@ -62,9 +63,22 @@ func (c *client) PutSpec(ctx context.Context, updateSpec sql.MetaSpecsUpdate) er
return err
}

// The error message returned from Snowflake for the multi-statement table
// creation queries is mostly a bunch of garbled nonsense about Javascript
// execution errors if the user doesn't have permission to create tables in the
// schema, but it does embed the useful part in the midst of all that. This is a
// common enough error mode that we do some extra processing for this case to
// make it more obvious what is happening.
var errInsufficientPrivileges = regexp.MustCompile(`Insufficient privileges to operate on schema '([^']+)'`)

func (c *client) CreateTable(ctx context.Context, tc sql.TableCreate) error {
_, err := c.db.ExecContext(ctx, tc.TableCreateSql)
return err
if _, err := c.db.ExecContext(ctx, tc.TableCreateSql); err != nil {
if matches := errInsufficientPrivileges.FindStringSubmatch(err.Error()); len(matches) > 0 {
err = errors.New(matches[0])
}
return err
}
return nil
}

func (c *client) DeleteTable(ctx context.Context, path []string) (string, boilerplate.ActionApplyFn, error) {
Expand Down

0 comments on commit 5f38d5c

Please sign in to comment.