From dec212a19df36135f08c7926c608c36b6d89fe7a Mon Sep 17 00:00:00 2001 From: nadavsteindler Date: Thu, 1 Aug 2024 11:08:37 +0300 Subject: [PATCH] createdb review fixes 7970 --- pkg/actions/lua/storage/aws/glue.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/actions/lua/storage/aws/glue.go b/pkg/actions/lua/storage/aws/glue.go index 203bab57a7a..c813a8ec966 100644 --- a/pkg/actions/lua/storage/aws/glue.go +++ b/pkg/actions/lua/storage/aws/glue.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "errors" - "github.com/Shopify/go-lua" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" @@ -233,7 +232,7 @@ func createDatabase(c *GlueClient) lua.Function { var createDBInput *glue.CreateDatabaseInput errorOnAlreadyExists := true - if !l.IsNone(2) { + if !l.IsNoneOrNil(2) { lua.CheckType(l, 2, lua.TypeTable) l.Field(2, "error_on_already_exists") l.Field(2, "create_db_input") @@ -266,7 +265,7 @@ func createDatabase(c *GlueClient) lua.Function { // AWS API call _, err := client.CreateDatabase(c.ctx, createDBInput) if err != nil { - if !errorOnAlreadyExists { + if !errorOnAlreadyExists && isAlreadyExistsErr(err) { return 0 } lua.Errorf(l, "%s", err.Error()) @@ -276,6 +275,11 @@ func createDatabase(c *GlueClient) lua.Function { } } +func isAlreadyExistsErr(err error) bool { + var errExists *types.AlreadyExistsException + return errors.As(err, &errExists) +} + func deleteDatabase(c *GlueClient) lua.Function { return func(l *lua.State) int { client := c.client()