1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Adjust assorted hint messages that list all valid options.

Instead of listing all valid options, we now try to provide one
that looks similar.  Since this may be useful elsewhere, this
change introduces a new set of functions that can be reused for
similar purposes.

Author: Nathan Bossart <nathandbossart@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/b1f9f399-3a1a-b554-283f-4ae7f34608e2@enterprisedb.com
This commit is contained in:
Peter Eisentraut
2022-09-16 14:51:47 +02:00
parent 1e08576691
commit 5ac51c8c9e
10 changed files with 159 additions and 47 deletions

View File

@ -90,26 +90,31 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
{
/*
* Unknown option specified, complain about it. Provide a hint
* with list of valid options for the object.
* with a valid option that looks similar, if there is one.
*/
PgFdwOption *opt;
StringInfoData buf;
const char *closest_match;
ClosestMatchState match_state;
bool has_valid_options = false;
initStringInfo(&buf);
initClosestMatch(&match_state, def->defname, 4);
for (opt = postgres_fdw_options; opt->keyword; opt++)
{
if (catalog == opt->optcontext)
appendStringInfo(&buf, "%s%s", (buf.len > 0) ? ", " : "",
opt->keyword);
{
has_valid_options = true;
updateClosestMatch(&match_state, opt->keyword);
}
}
closest_match = getClosestMatch(&match_state);
ereport(ERROR,
(errcode(ERRCODE_FDW_INVALID_OPTION_NAME),
errmsg("invalid option \"%s\"", def->defname),
buf.len > 0
? errhint("Valid options in this context are: %s",
buf.data)
: errhint("There are no valid options in this context.")));
has_valid_options ? closest_match ?
errhint("Perhaps you meant the option \"%s\".",
closest_match) : 0 :
errhint("There are no valid options in this context.")));
}
/*