summaryrefslogtreecommitdiff
path: root/src/bin/psql/startup.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-04-08 14:55:14 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2022-04-08 14:55:14 -0400
commit9a374b77fb53e4cfbca121e4fa278a7d71bde7c4 (patch)
tree6591af757bd9df12549279b4b87f01e0ce98bd79 /src/bin/psql/startup.c
parent5c431c7fb327e1abc70b7a197650f8d45fd5bede (diff)
Improve frontend error logging style.
Get rid of the separate "FATAL" log level, as it was applied so inconsistently as to be meaningless. This mostly involves s/pg_log_fatal/pg_log_error/g. Create a macro pg_fatal() to handle the common use-case of pg_log_error() immediately followed by exit(1). Various modules had already invented either this or equivalent macros; standardize on pg_fatal() and apply it where possible. Invent the ability to add "detail" and "hint" messages to a frontend message, much as we have long had in the backend. Except where rewording was needed to convert existing coding to detail/hint style, I have (mostly) resisted the temptation to change existing message wording. Patch by me. Design and patch reviewed at various stages by Robert Haas, Kyotaro Horiguchi, Peter Eisentraut and Daniel Gustafsson. Discussion: https://postgr.es/m/1363732.1636496441@sss.pgh.pa.us
Diffstat (limited to 'src/bin/psql/startup.c')
-rw-r--r--src/bin/psql/startup.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index d08b15886aa..ddff9039158 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -217,10 +217,7 @@ main(int argc, char *argv[])
/* Bail out if -1 was specified but will be ignored. */
if (options.single_txn && options.actions.head == NULL)
- {
- pg_log_fatal("-1 can only be used in non-interactive mode");
- exit(EXIT_FAILURE);
- }
+ pg_fatal("-1 can only be used in non-interactive mode");
if (!pset.popt.topt.fieldSep.separator &&
!pset.popt.topt.fieldSep.separator_zero)
@@ -343,11 +340,8 @@ main(int argc, char *argv[])
{
pset.logfile = fopen(options.logfilename, "a");
if (!pset.logfile)
- {
- pg_log_fatal("could not open log file \"%s\": %m",
- options.logfilename);
- exit(EXIT_FAILURE);
- }
+ pg_fatal("could not open log file \"%s\": %m",
+ options.logfilename);
}
if (!options.no_psqlrc)
@@ -608,10 +602,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts *options)
}
if (!result)
- {
- pg_log_fatal("could not set printing parameter \"%s\"", value);
- exit(EXIT_FAILURE);
- }
+ pg_fatal("could not set printing parameter \"%s\"", value);
free(value);
break;
@@ -717,10 +708,10 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts *options)
break;
default:
unknown_option:
- fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
- pset.progname);
+ /* getopt_long already emitted a complaint */
+ pg_log_error_hint("Try \"%s --help\" for more information.",
+ pset.progname);
exit(EXIT_FAILURE);
- break;
}
}
@@ -782,10 +773,7 @@ process_psqlrc(char *argv0)
char *envrc = getenv("PSQLRC");
if (find_my_exec(argv0, my_exec_path) < 0)
- {
- pg_log_fatal("could not find own program executable");
- exit(EXIT_FAILURE);
- }
+ pg_fatal("could not find own program executable");
get_etc_path(my_exec_path, etc_path);