Skip to content

Commit 5278222

Browse files
committed
Unify error messages
No visible changes, just refactor how messages are constructed.
1 parent d3ceb20 commit 5278222

File tree

11 files changed

+92
-51
lines changed

11 files changed

+92
-51
lines changed

src/backend/catalog/aclchk.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,8 @@ SetDefaultACL(InternalDefaultACL *iacls)
12081208
if (OidIsValid(iacls->nspid))
12091209
ereport(ERROR,
12101210
(errcode(ERRCODE_INVALID_GRANT_OPERATION),
1211-
errmsg("cannot use IN SCHEMA clause when using GRANT/REVOKE ON SCHEMAS")));
1211+
errmsg("cannot use IN SCHEMA clause when using %s",
1212+
"GRANT/REVOKE ON SCHEMAS")));
12121213
objtype = DEFACLOBJ_NAMESPACE;
12131214
if (iacls->all_privs && this_privileges == ACL_NO_RIGHTS)
12141215
this_privileges = ACL_ALL_RIGHTS_SCHEMA;
@@ -1218,7 +1219,8 @@ SetDefaultACL(InternalDefaultACL *iacls)
12181219
if (OidIsValid(iacls->nspid))
12191220
ereport(ERROR,
12201221
(errcode(ERRCODE_INVALID_GRANT_OPERATION),
1221-
errmsg("cannot use IN SCHEMA clause when using GRANT/REVOKE ON LARGE OBJECTS")));
1222+
errmsg("cannot use IN SCHEMA clause when using %s",
1223+
"GRANT/REVOKE ON LARGE OBJECTS")));
12221224
objtype = DEFACLOBJ_LARGEOBJECT;
12231225
if (iacls->all_privs && this_privileges == ACL_NO_RIGHTS)
12241226
this_privileges = ACL_ALL_RIGHTS_LARGEOBJECT;

src/backend/commands/cluster.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ cluster(ParseState *pstate, ClusterStmt *stmt, bool isTopLevel)
124124
else
125125
ereport(ERROR,
126126
(errcode(ERRCODE_SYNTAX_ERROR),
127-
errmsg("unrecognized CLUSTER option \"%s\"",
128-
opt->defname),
127+
errmsg("unrecognized %s option \"%s\"",
128+
"CLUSTER", opt->defname),
129129
parser_errposition(pstate, opt->location)));
130130
}
131131

src/backend/commands/dbcommands.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,8 @@ DropDatabase(ParseState *pstate, DropdbStmt *stmt)
23532353
else
23542354
ereport(ERROR,
23552355
(errcode(ERRCODE_SYNTAX_ERROR),
2356-
errmsg("unrecognized DROP DATABASE option \"%s\"", opt->defname),
2356+
errmsg("unrecognized %s option \"%s\"",
2357+
"DROP DATABASE", opt->defname),
23572358
parser_errposition(pstate, opt->location)));
23582359
}
23592360

src/backend/commands/explain_state.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ ParseExplainOptionList(ExplainState *es, List *options, ParseState *pstate)
130130
else
131131
ereport(ERROR,
132132
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
133-
errmsg("unrecognized value for EXPLAIN option \"%s\": \"%s\"",
134-
opt->defname, p),
133+
errmsg("unrecognized value for %s option \"%s\": \"%s\"",
134+
"EXPLAIN", opt->defname, p),
135135
parser_errposition(pstate, opt->location)));
136136
}
137137
else
@@ -155,15 +155,15 @@ ParseExplainOptionList(ExplainState *es, List *options, ParseState *pstate)
155155
else
156156
ereport(ERROR,
157157
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
158-
errmsg("unrecognized value for EXPLAIN option \"%s\": \"%s\"",
159-
opt->defname, p),
158+
errmsg("unrecognized value for %s option \"%s\": \"%s\"",
159+
"EXPLAIN", opt->defname, p),
160160
parser_errposition(pstate, opt->location)));
161161
}
162162
else if (!ApplyExtensionExplainOption(es, opt, pstate))
163163
ereport(ERROR,
164164
(errcode(ERRCODE_SYNTAX_ERROR),
165-
errmsg("unrecognized EXPLAIN option \"%s\"",
166-
opt->defname),
165+
errmsg("unrecognized %s option \"%s\"",
166+
"EXPLAIN", opt->defname),
167167
parser_errposition(pstate, opt->location)));
168168
}
169169

@@ -195,7 +195,8 @@ ParseExplainOptionList(ExplainState *es, List *options, ParseState *pstate)
195195
if (es->generic && es->analyze)
196196
ereport(ERROR,
197197
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
198-
errmsg("EXPLAIN options ANALYZE and GENERIC_PLAN cannot be used together")));
198+
errmsg("%s options %s and %s cannot be used together",
199+
"EXPLAIN", "ANALYZE", "GENERIC_PLAN")));
199200

200201
/* if the summary was not set explicitly, set default value */
201202
es->summary = (summary_set) ? es->summary : es->analyze;

src/backend/commands/indexcmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,8 +2843,8 @@ ExecReindex(ParseState *pstate, const ReindexStmt *stmt, bool isTopLevel)
28432843
else
28442844
ereport(ERROR,
28452845
(errcode(ERRCODE_SYNTAX_ERROR),
2846-
errmsg("unrecognized REINDEX option \"%s\"",
2847-
opt->defname),
2846+
errmsg("unrecognized %s option \"%s\"",
2847+
"REINDEX", opt->defname),
28482848
parser_errposition(pstate, opt->location)));
28492849
}
28502850

src/backend/commands/vacuum.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
231231
else if (!vacstmt->is_vacuumcmd)
232232
ereport(ERROR,
233233
(errcode(ERRCODE_SYNTAX_ERROR),
234-
errmsg("unrecognized ANALYZE option \"%s\"", opt->defname),
234+
errmsg("unrecognized %s option \"%s\"",
235+
"ANALYZE", opt->defname),
235236
parser_errposition(pstate, opt->location)));
236237

237238
/* Parse options available on VACUUM */
@@ -304,7 +305,8 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
304305
else
305306
ereport(ERROR,
306307
(errcode(ERRCODE_SYNTAX_ERROR),
307-
errmsg("unrecognized VACUUM option \"%s\"", opt->defname),
308+
errmsg("unrecognized %s option \"%s\"",
309+
"VACUUM", opt->defname),
308310
parser_errposition(pstate, opt->location)));
309311
}
310312

src/backend/replication/walsender.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,8 +1148,8 @@ parseCreateReplSlotOptions(CreateReplicationSlotCmd *cmd,
11481148
else
11491149
ereport(ERROR,
11501150
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1151-
errmsg("unrecognized value for CREATE_REPLICATION_SLOT option \"%s\": \"%s\"",
1152-
defel->defname, action)));
1151+
errmsg("unrecognized value for %s option \"%s\": \"%s\"",
1152+
"CREATE_REPLICATION_SLOT", defel->defname, action)));
11531153
}
11541154
else if (strcmp(defel->defname, "reserve_wal") == 0)
11551155
{

src/bin/pg_basebackup/pg_createsubscriber.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,8 @@ main(int argc, char **argv)
22562256

22572257
if (bad_switch)
22582258
{
2259-
pg_log_error("options %s and -a/--all cannot be used together", bad_switch);
2259+
pg_log_error("options %s and %s cannot be used together",
2260+
bad_switch, "-a/--all");
22602261
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
22612262
exit(1);
22622263
}
@@ -2382,7 +2383,8 @@ main(int argc, char **argv)
23822383
dbinfos.objecttypes_to_clean |= OBJECTTYPE_PUBLICATIONS;
23832384
else
23842385
{
2385-
pg_log_error("invalid object type \"%s\" specified for --clean", cell->val);
2386+
pg_log_error("invalid object type \"%s\" specified for %s",
2387+
cell->val, "--clean");
23862388
pg_log_error_hint("The valid value is: \"%s\"", "publications");
23872389
exit(1);
23882390
}

src/bin/pg_dump/pg_dump.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -823,23 +823,30 @@ main(int argc, char **argv)
823823

824824
/* reject conflicting "-only" options */
825825
if (data_only && schema_only)
826-
pg_fatal("options -s/--schema-only and -a/--data-only cannot be used together");
826+
pg_fatal("options %s and %s cannot be used together",
827+
"-s/--schema-only", "-a/--data-only");
827828
if (schema_only && statistics_only)
828-
pg_fatal("options -s/--schema-only and --statistics-only cannot be used together");
829+
pg_fatal("options %s and %s cannot be used together",
830+
"-s/--schema-only", "--statistics-only");
829831
if (data_only && statistics_only)
830-
pg_fatal("options -a/--data-only and --statistics-only cannot be used together");
832+
pg_fatal("options %s and %s cannot be used together",
833+
"-a/--data-only", "--statistics-only");
831834

832835
/* reject conflicting "-only" and "no-" options */
833836
if (data_only && no_data)
834-
pg_fatal("options -a/--data-only and --no-data cannot be used together");
837+
pg_fatal("options %s and %s cannot be used together",
838+
"-a/--data-only", "--no-data");
835839
if (schema_only && no_schema)
836-
pg_fatal("options -s/--schema-only and --no-schema cannot be used together");
840+
pg_fatal("options %s and %s cannot be used together",
841+
"-s/--schema-only", "--no-schema");
837842
if (statistics_only && no_statistics)
838-
pg_fatal("options --statistics-only and --no-statistics cannot be used together");
843+
pg_fatal("options %s and %s cannot be used together",
844+
"--statistics-only", "--no-statistics");
839845

840846
/* reject conflicting "no-" options */
841847
if (with_statistics && no_statistics)
842-
pg_fatal("options --statistics and --no-statistics cannot be used together");
848+
pg_fatal("options %s and %s cannot be used together",
849+
"--statistics", "--no-statistics");
843850

844851
/* reject conflicting "-only" options */
845852
if (data_only && with_statistics)
@@ -850,16 +857,20 @@ main(int argc, char **argv)
850857
"-s/--schema-only", "--statistics");
851858

852859
if (schema_only && foreign_servers_include_patterns.head != NULL)
853-
pg_fatal("options -s/--schema-only and --include-foreign-data cannot be used together");
860+
pg_fatal("options %s and %s cannot be used together",
861+
"-s/--schema-only", "--include-foreign-data");
854862

855863
if (numWorkers > 1 && foreign_servers_include_patterns.head != NULL)
856-
pg_fatal("option --include-foreign-data is not supported with parallel backup");
864+
pg_fatal("option %s is not supported with parallel backup",
865+
"--include-foreign-data");
857866

858867
if (data_only && dopt.outputClean)
859-
pg_fatal("options -c/--clean and -a/--data-only cannot be used together");
868+
pg_fatal("options %s and %s cannot be used together",
869+
"-c/--clean", "-a/--data-only");
860870

861871
if (dopt.if_exists && !dopt.outputClean)
862-
pg_fatal("option --if-exists requires option -c/--clean");
872+
pg_fatal("option %s requires option %s",
873+
"--if-exists", "-c/--clean");
863874

864875
/*
865876
* Set derivative flags. Ambiguous or nonsensical combinations, e.g.
@@ -879,7 +890,9 @@ main(int argc, char **argv)
879890
* --rows-per-insert were specified.
880891
*/
881892
if (dopt.do_nothing && dopt.dump_inserts == 0)
882-
pg_fatal("option --on-conflict-do-nothing requires option --inserts, --rows-per-insert, or --column-inserts");
893+
pg_fatal("option %s requires option %s, %s, or %s",
894+
"--on-conflict-do-nothing",
895+
"--inserts", "--rows-per-insert", "--column-inserts");
883896

884897
/* Identify archive format to emit */
885898
archiveFormat = parseArchiveFormat(format, &archiveMode);
@@ -900,7 +913,8 @@ main(int argc, char **argv)
900913
pg_fatal("invalid restrict key");
901914
}
902915
else if (dopt.restrict_key)
903-
pg_fatal("option --restrict-key can only be used with --format=plain");
916+
pg_fatal("option %s can only be used with %s",
917+
"--restrict-key", "--format=plain");
904918

905919
/*
906920
* Custom and directory formats are compressed by default with gzip when

src/bin/pg_dump/pg_dumpall.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,32 +399,38 @@ main(int argc, char *argv[])
399399
if (database_exclude_patterns.head != NULL &&
400400
(globals_only || roles_only || tablespaces_only))
401401
{
402-
pg_log_error("option --exclude-database cannot be used together with -g/--globals-only, -r/--roles-only, or -t/--tablespaces-only");
402+
pg_log_error("option %s cannot be used together with %s, %s, or %s",
403+
"--exclude-database",
404+
"-g/--globals-only", "-r/--roles-only", "-t/--tablespaces-only");
403405
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
404406
exit_nicely(1);
405407
}
406408

407409
/* Make sure the user hasn't specified a mix of globals-only options */
408410
if (globals_only && roles_only)
409411
{
410-
pg_log_error("options -g/--globals-only and -r/--roles-only cannot be used together");
412+
pg_log_error("options %s and %s cannot be used together",
413+
"-g/--globals-only", "-r/--roles-only");
411414
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
412415
exit_nicely(1);
413416
}
414417

415418
if (globals_only && tablespaces_only)
416419
{
417-
pg_log_error("options -g/--globals-only and -t/--tablespaces-only cannot be used together");
420+
pg_log_error("options %s and %s cannot be used together",
421+
"-g/--globals-only", "-t/--tablespaces-only");
418422
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
419423
exit_nicely(1);
420424
}
421425

422426
if (if_exists && !output_clean)
423-
pg_fatal("option --if-exists requires option -c/--clean");
427+
pg_fatal("option %s requires option %s",
428+
"--if-exists", "-c/--clean");
424429

425430
if (roles_only && tablespaces_only)
426431
{
427-
pg_log_error("options -r/--roles-only and -t/--tablespaces-only cannot be used together");
432+
pg_log_error("options %s and %s cannot be used together",
433+
"-r/--roles-only", "-t/--tablespaces-only");
428434
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
429435
exit_nicely(1);
430436
}

0 commit comments

Comments
 (0)