Skip to content

Commit 898c131

Browse files
author
Amit Kapila
committed
pg_createsubscriber: Improve error messages.
Consistently, an option name is used in the error messages where applicable. Also, change the code to use pg_fatal() instead of a combination of pg_log_error() and exit(). Author: vignesh C <[email protected]> Reviewed-by: Hayato Kuroda <[email protected]> Reviewed-by: Amit Kapila <[email protected]> Discussion: https://postgr.es/m/CALDaNm0HxF1RH27LP7VisLzNsSJbssy8a64M5p6UduDaBq6-ag@mail.gmail.com
1 parent d5d85f1 commit 898c131

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

src/bin/pg_basebackup/pg_createsubscriber.c

+7-19
Original file line numberDiff line numberDiff line change
@@ -2124,10 +2124,7 @@ main(int argc, char **argv)
21242124
num_dbs++;
21252125
}
21262126
else
2127-
{
2128-
pg_log_error("database \"%s\" specified more than once", optarg);
2129-
exit(1);
2130-
}
2127+
pg_fatal("database \"%s\" specified more than once for -d/--database", optarg);
21312128
break;
21322129
case 'D':
21332130
subscriber_dir = pg_strdup(optarg);
@@ -2146,7 +2143,7 @@ main(int argc, char **argv)
21462143
if (!simple_string_list_member(&opt.objecttypes_to_remove, optarg))
21472144
simple_string_list_append(&opt.objecttypes_to_remove, optarg);
21482145
else
2149-
pg_fatal("object type \"%s\" is specified more than once for --remove", optarg);
2146+
pg_fatal("object type \"%s\" is specified more than once for -R/--remove", optarg);
21502147
break;
21512148
case 's':
21522149
opt.socket_dir = pg_strdup(optarg);
@@ -2174,10 +2171,7 @@ main(int argc, char **argv)
21742171
num_pubs++;
21752172
}
21762173
else
2177-
{
2178-
pg_log_error("publication \"%s\" specified more than once", optarg);
2179-
exit(1);
2180-
}
2174+
pg_fatal("publication \"%s\" specified more than once for --publication", optarg);
21812175
break;
21822176
case 3:
21832177
if (!simple_string_list_member(&opt.replslot_names, optarg))
@@ -2186,10 +2180,7 @@ main(int argc, char **argv)
21862180
num_replslots++;
21872181
}
21882182
else
2189-
{
2190-
pg_log_error("replication slot \"%s\" specified more than once", optarg);
2191-
exit(1);
2192-
}
2183+
pg_fatal("replication slot \"%s\" specified more than once for --replication-slot", optarg);
21932184
break;
21942185
case 4:
21952186
if (!simple_string_list_member(&opt.sub_names, optarg))
@@ -2198,10 +2189,7 @@ main(int argc, char **argv)
21982189
num_subs++;
21992190
}
22002191
else
2201-
{
2202-
pg_log_error("subscription \"%s\" specified more than once", optarg);
2203-
exit(1);
2204-
}
2192+
pg_fatal("subscription \"%s\" specified more than once for --subscription", optarg);
22052193
break;
22062194
default:
22072195
/* getopt_long already emitted a complaint */
@@ -2226,7 +2214,7 @@ main(int argc, char **argv)
22262214

22272215
if (bad_switch)
22282216
{
2229-
pg_log_error("%s cannot be used with --all", bad_switch);
2217+
pg_log_error("%s cannot be used with -a/--all", bad_switch);
22302218
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
22312219
exit(1);
22322220
}
@@ -2352,7 +2340,7 @@ main(int argc, char **argv)
23522340
dbinfos.objecttypes_to_remove |= OBJECTTYPE_PUBLICATIONS;
23532341
else
23542342
{
2355-
pg_log_error("invalid object type \"%s\" specified for --remove", cell->val);
2343+
pg_log_error("invalid object type \"%s\" specified for -R/--remove", cell->val);
23562344
pg_log_error_hint("The valid option is: \"publications\"");
23572345
exit(1);
23582346
}

src/bin/pg_basebackup/t/040_pg_createsubscriber.pl

+2-2
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ sub generate_db
399399
'--database' => $db1,
400400
'--all',
401401
],
402-
qr/--database cannot be used with --all/,
402+
qr/--database cannot be used with -a\/--all/,
403403
'fail if --database is used with --all');
404404

405405
# run pg_createsubscriber with '--publication' and '--all' and verify
@@ -416,7 +416,7 @@ sub generate_db
416416
'--all',
417417
'--publication' => 'pub1',
418418
],
419-
qr/--publication cannot be used with --all/,
419+
qr/--publication cannot be used with -a\/--all/,
420420
'fail if --publication is used with --all');
421421

422422
# run pg_createsubscriber with '--all' option

0 commit comments

Comments
 (0)