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

12 files changed:
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/postmaster/checkpointer.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 cb496e018c590152e12fd04e60968556ca61d1f3..5b410ff14c9336d58003db22a9d3019fbbfdafd3 100644 (file)
@@ -1207,7 +1207,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;
@@ -1217,7 +1218,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 b55221d44cd00f4476c26429dd023141f25eadae..d1e772efb722b214aa0777a7957866bb51df9c8f 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 4d65e8c46c21ab476640066d45499498a18d271a..da85cd2d43527ebc7171b7a7cd3742b506b00b58 100644 (file)
@@ -2354,7 +2354,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 a8033be4bffb1e18f9b30ce9f4325be67acb77f3..d9cccb6ac1885b102386577aa107727116ec90f6 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 e785dd55ce563ae44eed4ac77b92c84b2762c147..29def1e94faa200b4e934c7fdee3c6dac509ce7e 100644 (file)
@@ -232,7 +232,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 */
@@ -294,7 +295,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 e84e8663e966bd33614a392d8a87dc33427e5355..fa4d7438442cf0e4ec65eac3213dddbc522c0086 100644 (file)
@@ -1027,7 +1027,8 @@ ExecCheckpoint(ParseState *pstate, CheckPointStmt *stmt)
        else
            ereport(ERROR,
                    (errcode(ERRCODE_SYNTAX_ERROR),
-                    errmsg("unrecognized CHECKPOINT option \"%s\"", opt->defname),
+                    errmsg("unrecognized %s option \"%s\"",
+                           "CHECKPOINT", opt->defname),
                     parser_errposition(pstate, opt->location)));
    }
 
index a1b4301a4ee288703cb5f8f16dda81cd26ed847f..0564c995500a916f91c0199f4169bb536ec84a28 100644 (file)
@@ -1152,8 +1152,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 43dc6ff7693980c7ff73df48ca7e5823f3618ae6..ef6deec14af8cfc87a18c86443d0c9b164cfb342 100644 (file)
@@ -2255,7 +2255,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);
        }
@@ -2386,7 +2387,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 2445085dbbd83a38c11875fb10f57bb881955f58..24ad201af2f986c5dce990edd71a5724254ce8b0 100644 (file)
@@ -831,23 +831,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)
@@ -858,16 +865,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.
@@ -887,7 +898,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);
@@ -908,7 +921,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;