diff options
| author | Tom Lane | 2022-04-08 18:55:14 +0000 |
|---|---|---|
| committer | Tom Lane | 2022-04-08 18:55:14 +0000 |
| commit | 9a374b77fb53e4cfbca121e4fa278a7d71bde7c4 (patch) | |
| tree | 6591af757bd9df12549279b4b87f01e0ce98bd79 /src/bin/psql | |
| parent | 5c431c7fb327e1abc70b7a197650f8d45fd5bede (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')
| -rw-r--r-- | src/bin/psql/command.c | 2 | ||||
| -rw-r--r-- | src/bin/psql/common.c | 2 | ||||
| -rw-r--r-- | src/bin/psql/help.c | 5 | ||||
| -rw-r--r-- | src/bin/psql/mainloop.c | 10 | ||||
| -rw-r--r-- | src/bin/psql/startup.c | 28 | ||||
| -rw-r--r-- | src/bin/psql/t/001_basic.pl | 2 |
6 files changed, 14 insertions, 35 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index db071d561fe..b51d28780b1 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -232,7 +232,7 @@ HandleSlashCmds(PsqlScanState scan_state, { pg_log_error("invalid command \\%s", cmd); if (pset.cur_cmd_interactive) - pg_log_info("Try \\? for help."); + pg_log_error_hint("Try \\? for help."); status = PSQL_CMD_ERROR; } diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 5a707dab648..feb1d547d4d 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -304,7 +304,7 @@ CheckConnection(void) { if (!pset.cur_cmd_interactive) { - pg_log_fatal("connection to server was lost"); + pg_log_error("connection to server was lost"); exit(EXIT_BADCONN); } diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index 1d3601e5942..49eb116f33b 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -58,10 +58,7 @@ usage(unsigned short int pager) { user = get_user_name(&errstr); if (!user) - { - pg_log_fatal("%s", errstr); - exit(EXIT_FAILURE); - } + pg_fatal("%s", errstr); } /* diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c index e5c976fc4fc..b0c4177a20e 100644 --- a/src/bin/psql/mainloop.c +++ b/src/bin/psql/mainloop.c @@ -77,10 +77,7 @@ MainLoop(FILE *source) if (PQExpBufferBroken(query_buf) || PQExpBufferBroken(previous_buf) || PQExpBufferBroken(history_buf)) - { - pg_log_error("out of memory"); - exit(EXIT_FAILURE); - } + pg_fatal("out of memory"); /* main loop to get queries and execute them */ while (successResult == EXIT_SUCCESS) @@ -398,10 +395,7 @@ MainLoop(FILE *source) prompt_status = prompt_tmp; if (PQExpBufferBroken(query_buf)) - { - pg_log_error("out of memory"); - exit(EXIT_FAILURE); - } + pg_fatal("out of memory"); /* * Increase statement line number counter for each linebreak added 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); diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl index 8ecb9b2583b..98996d9a379 100644 --- a/src/bin/psql/t/001_basic.pl +++ b/src/bin/psql/t/001_basic.pl @@ -129,7 +129,7 @@ is($err, 'psql:<stdin>:2: FATAL: terminating connection due to administrator co psql:<stdin>:2: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. -psql:<stdin>:2: fatal: connection to server was lost', +psql:<stdin>:2: error: connection to server was lost', 'server crash: error message'); # test \errverbose |
