Skip to content

Commit

Permalink
fix: add error checks for pg function
Browse files Browse the repository at this point in the history
  • Loading branch information
khkhalifa committed Jan 13, 2023
1 parent 916a36e commit cb57630
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 1 addition & 4 deletions postgresql/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,5 @@ func findStringSubmatchMap(expression string, text string) map[string]string {
}

func defaultDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool {
if old == new {
return true
}
return false
return old == new
}
5 changes: 4 additions & 1 deletion postgresql/model_pg_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ func (pgFunction *PGFunction) Parse(functionDefinition string) error {
rawArgs := strings.Split(argsData, ",")
for i := 0; i < len(rawArgs); i++ {
var arg PGFunctionArg
arg.Parse(rawArgs[i])
err := arg.Parse(rawArgs[i])
if err != nil {
continue
}
args = append(args, arg)
}
}
Expand Down
15 changes: 12 additions & 3 deletions postgresql/resource_postgresql_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ func resourcePostgreSQLFunctionReadImpl(db *DBConnection, d *schema.ResourceData

var pgFunction PGFunction

pgFunction.Parse(funcDefinition)
err = pgFunction.Parse(funcDefinition)
if err != nil {
return err
}

var args []map[string]interface{}

Expand Down Expand Up @@ -331,7 +334,10 @@ func resourcePostgreSQLFunctionUpdate(db *DBConnection, d *schema.ResourceData)
func createFunction(db *DBConnection, d *schema.ResourceData, replace bool) error {

var pgFunction PGFunction
pgFunction.FromResourceData(d)
err := pgFunction.FromResourceData(d)
if err != nil {
return err
}

b := bytes.NewBufferString("CREATE ")

Expand Down Expand Up @@ -408,7 +414,10 @@ func generateFunctionID(db *DBConnection, d *schema.ResourceData) string {
}

var pgFunction PGFunction
pgFunction.FromResourceData(d)
err = pgFunction.FromResourceData(d)
if err != nil {
return err
}

fmt.Fprint(b, pgFunction.Schema, ".", pgFunction.Name, "(")

Expand Down

0 comments on commit cb57630

Please sign in to comment.