From 5278222853cab4d9779b707eaea5878856e2471e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=81lvaro=20Herrera?= Date: Mon, 8 Dec 2025 16:30:52 +0100 Subject: [PATCH] Unify error messages No visible changes, just refactor how messages are constructed. --- src/backend/catalog/aclchk.c | 6 ++-- src/backend/commands/cluster.c | 4 +-- src/backend/commands/dbcommands.c | 3 +- src/backend/commands/explain_state.c | 15 ++++---- src/backend/commands/indexcmds.c | 4 +-- src/backend/commands/vacuum.c | 6 ++-- src/backend/replication/walsender.c | 4 +-- src/bin/pg_basebackup/pg_createsubscriber.c | 6 ++-- src/bin/pg_dump/pg_dump.c | 40 ++++++++++++++------- src/bin/pg_dump/pg_dumpall.c | 16 ++++++--- src/bin/pg_dump/pg_restore.c | 39 +++++++++++++------- 11 files changed, 92 insertions(+), 51 deletions(-) diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c index 24948c1f05e..17816481760 100644 --- a/src/backend/catalog/aclchk.c +++ b/src/backend/catalog/aclchk.c @@ -1208,7 +1208,8 @@ SetDefaultACL(InternalDefaultACL *iacls) if (OidIsValid(iacls->nspid)) ereport(ERROR, (errcode(ERRCODE_INVALID_GRANT_OPERATION), - errmsg("cannot use IN SCHEMA clause when using GRANT/REVOKE ON SCHEMAS"))); + errmsg("cannot use IN SCHEMA clause when using %s", + "GRANT/REVOKE ON SCHEMAS"))); objtype = DEFACLOBJ_NAMESPACE; if (iacls->all_privs && this_privileges == ACL_NO_RIGHTS) this_privileges = ACL_ALL_RIGHTS_SCHEMA; @@ -1218,7 +1219,8 @@ SetDefaultACL(InternalDefaultACL *iacls) if (OidIsValid(iacls->nspid)) ereport(ERROR, (errcode(ERRCODE_INVALID_GRANT_OPERATION), - errmsg("cannot use IN SCHEMA clause when using GRANT/REVOKE ON LARGE OBJECTS"))); + errmsg("cannot use IN SCHEMA clause when using %s", + "GRANT/REVOKE ON LARGE OBJECTS"))); objtype = DEFACLOBJ_LARGEOBJECT; if (iacls->all_privs && this_privileges == ACL_NO_RIGHTS) this_privileges = ACL_ALL_RIGHTS_LARGEOBJECT; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 54a08e4102e..94a5aee90b5 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -124,8 +124,8 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel) else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("unrecognized CLUSTER option \"%s\"", - opt->defname), + errmsg("unrecognized %s option \"%s\"", + "CLUSTER", opt->defname), parser_errposition(pstate, opt->location))); } diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 5a46002c60b..5eb6caffe6d 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -2353,7 +2353,8 @@ DropDatabase(ParseState *pstate, DropdbStmt *stmt) else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("unrecognized DROP DATABASE option \"%s\"", opt->defname), + errmsg("unrecognized %s option \"%s\"", + "DROP DATABASE", opt->defname), parser_errposition(pstate, opt->location))); } diff --git a/src/backend/commands/explain_state.c b/src/backend/commands/explain_state.c index 9fdeeab6436..dae256809d2 100644 --- a/src/backend/commands/explain_state.c +++ b/src/backend/commands/explain_state.c @@ -130,8 +130,8 @@ ParseExplainOptionList(ExplainState *es, List *options, ParseState *pstate) else ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("unrecognized value for EXPLAIN option \"%s\": \"%s\"", - opt->defname, p), + errmsg("unrecognized value for %s option \"%s\": \"%s\"", + "EXPLAIN", opt->defname, p), parser_errposition(pstate, opt->location))); } else @@ -155,15 +155,15 @@ ParseExplainOptionList(ExplainState *es, List *options, ParseState *pstate) else ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("unrecognized value for EXPLAIN option \"%s\": \"%s\"", - opt->defname, p), + errmsg("unrecognized value for %s option \"%s\": \"%s\"", + "EXPLAIN", opt->defname, p), parser_errposition(pstate, opt->location))); } else if (!ApplyExtensionExplainOption(es, opt, pstate)) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("unrecognized EXPLAIN option \"%s\"", - opt->defname), + errmsg("unrecognized %s option \"%s\"", + "EXPLAIN", opt->defname), parser_errposition(pstate, opt->location))); } @@ -195,7 +195,8 @@ ParseExplainOptionList(ExplainState *es, List *options, ParseState *pstate) if (es->generic && es->analyze) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("EXPLAIN options ANALYZE and GENERIC_PLAN cannot be used together"))); + errmsg("%s options %s and %s cannot be used together", + "EXPLAIN", "ANALYZE", "GENERIC_PLAN"))); /* if the summary was not set explicitly, set default value */ es->summary = (summary_set) ? es->summary : es->analyze; diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 6f753ab6d7a..22ccbad7d39 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -2843,8 +2843,8 @@ ExecReindex(ParseState *pstate, const ReindexStmt *stmt, bool isTopLevel) else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("unrecognized REINDEX option \"%s\"", - opt->defname), + errmsg("unrecognized %s option \"%s\"", + "REINDEX", opt->defname), parser_errposition(pstate, opt->location))); } diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 1d75d091a76..be863db81cb 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -231,7 +231,8 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel) else if (!vacstmt->is_vacuumcmd) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("unrecognized ANALYZE option \"%s\"", opt->defname), + errmsg("unrecognized %s option \"%s\"", + "ANALYZE", opt->defname), parser_errposition(pstate, opt->location))); /* Parse options available on VACUUM */ @@ -304,7 +305,8 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel) else ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("unrecognized VACUUM option \"%s\"", opt->defname), + errmsg("unrecognized %s option \"%s\"", + "VACUUM", opt->defname), parser_errposition(pstate, opt->location))); } diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 45b4e9eb153..3a076f447ef 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1148,8 +1148,8 @@ parseCreateReplSlotOptions(CreateReplicationSlotCmd *cmd, else ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("unrecognized value for CREATE_REPLICATION_SLOT option \"%s\": \"%s\"", - defel->defname, action))); + errmsg("unrecognized value for %s option \"%s\": \"%s\"", + "CREATE_REPLICATION_SLOT", defel->defname, action))); } else if (strcmp(defel->defname, "reserve_wal") == 0) { diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c index 95f127d09fc..e06439c1e95 100644 --- a/src/bin/pg_basebackup/pg_createsubscriber.c +++ b/src/bin/pg_basebackup/pg_createsubscriber.c @@ -2256,7 +2256,8 @@ main(int argc, char **argv) if (bad_switch) { - pg_log_error("options %s and -a/--all cannot be used together", bad_switch); + pg_log_error("options %s and %s cannot be used together", + bad_switch, "-a/--all"); pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } @@ -2382,7 +2383,8 @@ main(int argc, char **argv) dbinfos.objecttypes_to_clean |= OBJECTTYPE_PUBLICATIONS; else { - pg_log_error("invalid object type \"%s\" specified for --clean", cell->val); + pg_log_error("invalid object type \"%s\" specified for %s", + cell->val, "--clean"); pg_log_error_hint("The valid value is: \"%s\"", "publications"); exit(1); } diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 35e7581d66d..8765377341c 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -823,23 +823,30 @@ main(int argc, char **argv) /* reject conflicting "-only" options */ if (data_only && schema_only) - pg_fatal("options -s/--schema-only and -a/--data-only cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-s/--schema-only", "-a/--data-only"); if (schema_only && statistics_only) - pg_fatal("options -s/--schema-only and --statistics-only cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-s/--schema-only", "--statistics-only"); if (data_only && statistics_only) - pg_fatal("options -a/--data-only and --statistics-only cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-a/--data-only", "--statistics-only"); /* reject conflicting "-only" and "no-" options */ if (data_only && no_data) - pg_fatal("options -a/--data-only and --no-data cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-a/--data-only", "--no-data"); if (schema_only && no_schema) - pg_fatal("options -s/--schema-only and --no-schema cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-s/--schema-only", "--no-schema"); if (statistics_only && no_statistics) - pg_fatal("options --statistics-only and --no-statistics cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "--statistics-only", "--no-statistics"); /* reject conflicting "no-" options */ if (with_statistics && no_statistics) - pg_fatal("options --statistics and --no-statistics cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "--statistics", "--no-statistics"); /* reject conflicting "-only" options */ if (data_only && with_statistics) @@ -850,16 +857,20 @@ main(int argc, char **argv) "-s/--schema-only", "--statistics"); if (schema_only && foreign_servers_include_patterns.head != NULL) - pg_fatal("options -s/--schema-only and --include-foreign-data cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-s/--schema-only", "--include-foreign-data"); if (numWorkers > 1 && foreign_servers_include_patterns.head != NULL) - pg_fatal("option --include-foreign-data is not supported with parallel backup"); + pg_fatal("option %s is not supported with parallel backup", + "--include-foreign-data"); if (data_only && dopt.outputClean) - pg_fatal("options -c/--clean and -a/--data-only cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-c/--clean", "-a/--data-only"); if (dopt.if_exists && !dopt.outputClean) - pg_fatal("option --if-exists requires option -c/--clean"); + pg_fatal("option %s requires option %s", + "--if-exists", "-c/--clean"); /* * Set derivative flags. Ambiguous or nonsensical combinations, e.g. @@ -879,7 +890,9 @@ main(int argc, char **argv) * --rows-per-insert were specified. */ if (dopt.do_nothing && dopt.dump_inserts == 0) - pg_fatal("option --on-conflict-do-nothing requires option --inserts, --rows-per-insert, or --column-inserts"); + pg_fatal("option %s requires option %s, %s, or %s", + "--on-conflict-do-nothing", + "--inserts", "--rows-per-insert", "--column-inserts"); /* Identify archive format to emit */ archiveFormat = parseArchiveFormat(format, &archiveMode); @@ -900,7 +913,8 @@ main(int argc, char **argv) pg_fatal("invalid restrict key"); } else if (dopt.restrict_key) - pg_fatal("option --restrict-key can only be used with --format=plain"); + pg_fatal("option %s can only be used with %s", + "--restrict-key", "--format=plain"); /* * Custom and directory formats are compressed by default with gzip when diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index bb451c1bae1..8fa04930399 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -399,7 +399,9 @@ main(int argc, char *argv[]) if (database_exclude_patterns.head != NULL && (globals_only || roles_only || tablespaces_only)) { - pg_log_error("option --exclude-database cannot be used together with -g/--globals-only, -r/--roles-only, or -t/--tablespaces-only"); + pg_log_error("option %s cannot be used together with %s, %s, or %s", + "--exclude-database", + "-g/--globals-only", "-r/--roles-only", "-t/--tablespaces-only"); pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit_nicely(1); } @@ -407,24 +409,28 @@ main(int argc, char *argv[]) /* Make sure the user hasn't specified a mix of globals-only options */ if (globals_only && roles_only) { - pg_log_error("options -g/--globals-only and -r/--roles-only cannot be used together"); + pg_log_error("options %s and %s cannot be used together", + "-g/--globals-only", "-r/--roles-only"); pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit_nicely(1); } if (globals_only && tablespaces_only) { - pg_log_error("options -g/--globals-only and -t/--tablespaces-only cannot be used together"); + pg_log_error("options %s and %s cannot be used together", + "-g/--globals-only", "-t/--tablespaces-only"); pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit_nicely(1); } if (if_exists && !output_clean) - pg_fatal("option --if-exists requires option -c/--clean"); + pg_fatal("option %s requires option %s", + "--if-exists", "-c/--clean"); if (roles_only && tablespaces_only) { - pg_log_error("options -r/--roles-only and -t/--tablespaces-only cannot be used together"); + pg_log_error("options %s and %s cannot be used together", + "-r/--roles-only", "-t/--tablespaces-only"); pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit_nicely(1); } diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index c9776306c5c..84b8d410c9e 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -352,13 +352,15 @@ main(int argc, char **argv) { if (opts->filename) { - pg_log_error("options -d/--dbname and -f/--file cannot be used together"); + pg_log_error("options %s and %s cannot be used together", + "-d/--dbname", "-f/--file"); pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit_nicely(1); } if (opts->restrict_key) - pg_fatal("options -d/--dbname and --restrict-key cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-d/--dbname", "--restrict-key"); opts->useDB = 1; } @@ -377,23 +379,30 @@ main(int argc, char **argv) /* reject conflicting "-only" options */ if (data_only && schema_only) - pg_fatal("options -s/--schema-only and -a/--data-only cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-s/--schema-only", "-a/--data-only"); if (schema_only && statistics_only) - pg_fatal("options -s/--schema-only and --statistics-only cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-s/--schema-only", "--statistics-only"); if (data_only && statistics_only) - pg_fatal("options -a/--data-only and --statistics-only cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-a/--data-only", "--statistics-only"); /* reject conflicting "-only" and "no-" options */ if (data_only && no_data) - pg_fatal("options -a/--data-only and --no-data cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-a/--data-only", "--no-data"); if (schema_only && no_schema) - pg_fatal("options -s/--schema-only and --no-schema cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-s/--schema-only", "--no-schema"); if (statistics_only && no_statistics) - pg_fatal("options --statistics-only and --no-statistics cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "--statistics-only", "--no-statistics"); /* reject conflicting "no-" options */ if (with_statistics && no_statistics) - pg_fatal("options --statistics and --no-statistics cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "--statistics", "--no-statistics"); /* reject conflicting "only-" options */ if (data_only && with_statistics) @@ -404,17 +413,20 @@ main(int argc, char **argv) "-s/--schema-only", "--statistics"); if (data_only && opts->dropSchema) - pg_fatal("options -c/--clean and -a/--data-only cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-c/--clean", "-a/--data-only"); if (opts->single_txn && opts->txn_size > 0) - pg_fatal("options -1/--single-transaction and --transaction-size cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-1/--single-transaction", "--transaction-size"); /* * -C is not compatible with -1, because we can't create a database inside * a transaction block. */ if (opts->createDB && opts->single_txn) - pg_fatal("options -C/--create and -1/--single-transaction cannot be used together"); + pg_fatal("options %s and %s cannot be used together", + "-C/--create", "-1/--single-transaction"); /* Can't do single-txn mode with multiple connections */ if (opts->single_txn && numWorkers > 1) @@ -445,7 +457,8 @@ main(int argc, char **argv) opts->no_subscriptions = no_subscriptions; if (if_exists && !opts->dropSchema) - pg_fatal("option --if-exists requires option -c/--clean"); + pg_fatal("option %s requires option %s", + "--if-exists", "-c/--clean"); opts->if_exists = if_exists; opts->strict_names = strict_names; -- 2.39.5