diff options
author | Dean Rasheed <dean.a.rasheed@gmail.com> | 2021-07-15 08:49:45 +0100 |
---|---|---|
committer | Dean Rasheed <dean.a.rasheed@gmail.com> | 2021-07-15 08:49:45 +0100 |
commit | 2bfb50b3df11399ed80347dd03bfaf8cd5acf962 (patch) | |
tree | 126051120d4735ba8619d4102a65e92d366f36e0 /src/backend/commands/foreigncmds.c | |
parent | ffc9ddaea33f6dfd3dfa95828a0970fbb617bf8a (diff) | |
download | postgresql-2bfb50b3df11399ed80347dd03bfaf8cd5acf962.tar.gz postgresql-2bfb50b3df11399ed80347dd03bfaf8cd5acf962.zip |
Improve reporting of "conflicting or redundant options" errors.
When reporting "conflicting or redundant options" errors, try to
ensure that errposition() is used, to help the user identify the
offending option.
Formerly, errposition() was invoked in less than 60% of cases. This
patch raises that to over 90%, but there remain a few places where the
ParseState is not readily available. Using errdetail() might improve
the error in such cases, but that is left as a task for the future.
Additionally, since this error is thrown from over 100 places in the
codebase, introduce a dedicated function to throw it, reducing code
duplication.
Extracted from a slightly larger patch by Vignesh C. Reviewed by
Bharath Rupireddy, Alvaro Herrera, Dilip Kumar, Hou Zhijie, Peter
Smith, Daniel Gustafsson, Julien Rouhaud and me.
Discussion: https://postgr.es/m/CALDaNm33FFSS5tVyvmkoK2cCMuDVxcui=gFrjti9ROfynqSAGA@mail.gmail.com
Diffstat (limited to 'src/backend/commands/foreigncmds.c')
-rw-r--r-- | src/backend/commands/foreigncmds.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/backend/commands/foreigncmds.c b/src/backend/commands/foreigncmds.c index bc36311d383..9b71beb1d38 100644 --- a/src/backend/commands/foreigncmds.c +++ b/src/backend/commands/foreigncmds.c @@ -515,7 +515,7 @@ lookup_fdw_validator_func(DefElem *validator) * Process function options of CREATE/ALTER FDW */ static void -parse_func_options(List *func_options, +parse_func_options(ParseState *pstate, List *func_options, bool *handler_given, Oid *fdwhandler, bool *validator_given, Oid *fdwvalidator) { @@ -534,18 +534,14 @@ parse_func_options(List *func_options, if (strcmp(def->defname, "handler") == 0) { if (*handler_given) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("conflicting or redundant options"))); + errorConflictingDefElem(def, pstate); *handler_given = true; *fdwhandler = lookup_fdw_handler_func(def); } else if (strcmp(def->defname, "validator") == 0) { if (*validator_given) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("conflicting or redundant options"))); + errorConflictingDefElem(def, pstate); *validator_given = true; *fdwvalidator = lookup_fdw_validator_func(def); } @@ -559,7 +555,7 @@ parse_func_options(List *func_options, * Create a foreign-data wrapper */ ObjectAddress -CreateForeignDataWrapper(CreateFdwStmt *stmt) +CreateForeignDataWrapper(ParseState *pstate, CreateFdwStmt *stmt) { Relation rel; Datum values[Natts_pg_foreign_data_wrapper]; @@ -611,7 +607,7 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt) values[Anum_pg_foreign_data_wrapper_fdwowner - 1] = ObjectIdGetDatum(ownerId); /* Lookup handler and validator functions, if given */ - parse_func_options(stmt->func_options, + parse_func_options(pstate, stmt->func_options, &handler_given, &fdwhandler, &validator_given, &fdwvalidator); @@ -675,7 +671,7 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt) * Alter foreign-data wrapper */ ObjectAddress -AlterForeignDataWrapper(AlterFdwStmt *stmt) +AlterForeignDataWrapper(ParseState *pstate, AlterFdwStmt *stmt) { Relation rel; HeapTuple tp; @@ -717,7 +713,7 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt) memset(repl_null, false, sizeof(repl_null)); memset(repl_repl, false, sizeof(repl_repl)); - parse_func_options(stmt->func_options, + parse_func_options(pstate, stmt->func_options, &handler_given, &fdwhandler, &validator_given, &fdwvalidator); |