Unify error messages
authorÁlvaro Herrera <[email protected]>
Mon, 8 Dec 2025 15:30:52 +0000 (16:30 +0100)
committerÁlvaro Herrera <[email protected]>
Mon, 8 Dec 2025 15:30:52 +0000 (16:30 +0100)
No visible changes, just refactor how messages are constructed.

src/backend/catalog/aclchk.c
src/backend/commands/cluster.c
src/backend/commands/dbcommands.c
src/backend/commands/explain_state.c
src/backend/commands/indexcmds.c
src/backend/commands/vacuum.c
src/backend/replication/walsender.c
src/bin/pg_basebackup/pg_createsubscriber.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dumpall.c
src/bin/pg_dump/pg_restore.c

index 24948c1f05ee5cdea12d4fe1d3219b746d0df811..1781648176096a3aa53b72c87cab5ff1ce9f95ed 100644 (file)
@@ -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;
index 54a08e4102e14ec352b33340a3094951387819fd..94a5aee90b50b60cd9e0023a9a90814efa523297 100644 (file)
@@ -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)));
    }
 
index 5a46002c60ba2d9751d6590e3bb968cffd335861..5eb6caffe6d1aaadc60ce0efb40eb41d50df2302 100644 (file)
@@ -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)));
    }
 
index 9fdeeab6436fd0e667c3b6f74ad9b34b31dc5952..dae256809d27f6683c6f7a46f0be54f5f233bf47 100644 (file)
@@ -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;
index 6f753ab6d7a0dd527ce8d57d0227d66eb3a4b2a4..22ccbad7d3981dafaab635135104b0416b9d926e 100644 (file)
@@ -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)));
    }
 
index 1d75d091a767dbea38825c7ae1026ec4b2602534..be863db81cb6a92c6a7c85006d153d1af5c8e088 100644 (file)
@@ -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)));
    }
 
index 45b4e9eb15367c8acc99f3e9e89a2deb85343165..3a076f447ef36363e383236dfd12dc9af353a4a6 100644 (file)
@@ -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)
        {
index 95f127d09fcf970fce5f153a93d320dd4b8b6ea8..e06439c1e9517e8acac2bcf44e34b06108a68dfa 100644 (file)
@@ -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);
        }
index 35e7581d66da90639ee808b784aa71017e3b269f..8765377341c4dde798d3e0093c8484d2f0f62d95 100644 (file)
@@ -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
index bb451c1bae14465e5344b728f5e10e9796798a26..8fa0493039901cfbef6e154af940bcf3d0ae2e8f 100644 (file)
@@ -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);
    }
index c9776306c5c429ccc1e2ea2ad102c93444e527ab..84b8d410c9ef417db50cb499192c715c9c0e037e 100644 (file)
@@ -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;