From 5f38d5c6cb3afcc6c751491de2f31e8969e3ba28 Mon Sep 17 00:00:00 2001 From: Will Baker Date: Tue, 1 Oct 2024 14:06:44 -0400 Subject: [PATCH] materialize-snowflake: better error message for table creation access issue Provide a better error message if the user does not have permission to create a table in the selected schema. --- materialize-snowflake/client.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/materialize-snowflake/client.go b/materialize-snowflake/client.go index 91d5a44e97..0a99c75094 100644 --- a/materialize-snowflake/client.go +++ b/materialize-snowflake/client.go @@ -5,6 +5,7 @@ import ( stdsql "database/sql" "errors" "fmt" + "regexp" "strings" boilerplate "github.com/estuary/connectors/materialize-boilerplate" @@ -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) {