1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-18 13:44:19 +03:00

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 <vignesh21@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/CALDaNm0HxF1RH27LP7VisLzNsSJbssy8a64M5p6UduDaBq6-ag@mail.gmail.com
This commit is contained in:
Amit Kapila 2025-04-04 10:58:59 +05:30
parent d5d85f1881
commit 898c131b58
2 changed files with 9 additions and 21 deletions

View File

@ -2124,10 +2124,7 @@ main(int argc, char **argv)
num_dbs++; num_dbs++;
} }
else else
{ pg_fatal("database \"%s\" specified more than once for -d/--database", optarg);
pg_log_error("database \"%s\" specified more than once", optarg);
exit(1);
}
break; break;
case 'D': case 'D':
subscriber_dir = pg_strdup(optarg); subscriber_dir = pg_strdup(optarg);
@ -2146,7 +2143,7 @@ main(int argc, char **argv)
if (!simple_string_list_member(&opt.objecttypes_to_remove, optarg)) if (!simple_string_list_member(&opt.objecttypes_to_remove, optarg))
simple_string_list_append(&opt.objecttypes_to_remove, optarg); simple_string_list_append(&opt.objecttypes_to_remove, optarg);
else else
pg_fatal("object type \"%s\" is specified more than once for --remove", optarg); pg_fatal("object type \"%s\" is specified more than once for -R/--remove", optarg);
break; break;
case 's': case 's':
opt.socket_dir = pg_strdup(optarg); opt.socket_dir = pg_strdup(optarg);
@ -2174,10 +2171,7 @@ main(int argc, char **argv)
num_pubs++; num_pubs++;
} }
else else
{ pg_fatal("publication \"%s\" specified more than once for --publication", optarg);
pg_log_error("publication \"%s\" specified more than once", optarg);
exit(1);
}
break; break;
case 3: case 3:
if (!simple_string_list_member(&opt.replslot_names, optarg)) if (!simple_string_list_member(&opt.replslot_names, optarg))
@ -2186,10 +2180,7 @@ main(int argc, char **argv)
num_replslots++; num_replslots++;
} }
else else
{ pg_fatal("replication slot \"%s\" specified more than once for --replication-slot", optarg);
pg_log_error("replication slot \"%s\" specified more than once", optarg);
exit(1);
}
break; break;
case 4: case 4:
if (!simple_string_list_member(&opt.sub_names, optarg)) if (!simple_string_list_member(&opt.sub_names, optarg))
@ -2198,10 +2189,7 @@ main(int argc, char **argv)
num_subs++; num_subs++;
} }
else else
{ pg_fatal("subscription \"%s\" specified more than once for --subscription", optarg);
pg_log_error("subscription \"%s\" specified more than once", optarg);
exit(1);
}
break; break;
default: default:
/* getopt_long already emitted a complaint */ /* getopt_long already emitted a complaint */
@ -2226,7 +2214,7 @@ main(int argc, char **argv)
if (bad_switch) if (bad_switch)
{ {
pg_log_error("%s cannot be used with --all", bad_switch); pg_log_error("%s cannot be used with -a/--all", bad_switch);
pg_log_error_hint("Try \"%s --help\" for more information.", progname); pg_log_error_hint("Try \"%s --help\" for more information.", progname);
exit(1); exit(1);
} }
@ -2352,7 +2340,7 @@ main(int argc, char **argv)
dbinfos.objecttypes_to_remove |= OBJECTTYPE_PUBLICATIONS; dbinfos.objecttypes_to_remove |= OBJECTTYPE_PUBLICATIONS;
else else
{ {
pg_log_error("invalid object type \"%s\" specified for --remove", cell->val); pg_log_error("invalid object type \"%s\" specified for -R/--remove", cell->val);
pg_log_error_hint("The valid option is: \"publications\""); pg_log_error_hint("The valid option is: \"publications\"");
exit(1); exit(1);
} }

View File

@ -399,7 +399,7 @@ command_fails_like(
'--database' => $db1, '--database' => $db1,
'--all', '--all',
], ],
qr/--database cannot be used with --all/, qr/--database cannot be used with -a\/--all/,
'fail if --database is used with --all'); 'fail if --database is used with --all');
# run pg_createsubscriber with '--publication' and '--all' and verify # run pg_createsubscriber with '--publication' and '--all' and verify
@ -416,7 +416,7 @@ command_fails_like(
'--all', '--all',
'--publication' => 'pub1', '--publication' => 'pub1',
], ],
qr/--publication cannot be used with --all/, qr/--publication cannot be used with -a\/--all/,
'fail if --publication is used with --all'); 'fail if --publication is used with --all');
# run pg_createsubscriber with '--all' option # run pg_createsubscriber with '--all' option