From 9a374b77fb53e4cfbca121e4fa278a7d71bde7c4 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 8 Apr 2022 14:55:14 -0400 Subject: 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 --- src/fe_utils/archive.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'src/fe_utils/archive.c') diff --git a/src/fe_utils/archive.c b/src/fe_utils/archive.c index 361c1c25ead..53d42c2be41 100644 --- a/src/fe_utils/archive.c +++ b/src/fe_utils/archive.c @@ -49,10 +49,7 @@ RestoreArchivedFile(const char *path, const char *xlogfname, xlogRestoreCmd = BuildRestoreCommand(restoreCommand, xlogpath, xlogfname, NULL); if (xlogRestoreCmd == NULL) - { - pg_log_fatal("cannot use restore_command with %%r placeholder"); - exit(1); - } + pg_fatal("cannot use restore_command with %%r placeholder"); /* * Execute restore_command, which should copy the missing file from @@ -70,22 +67,16 @@ RestoreArchivedFile(const char *path, const char *xlogfname, if (stat(xlogpath, &stat_buf) == 0) { if (expectedSize > 0 && stat_buf.st_size != expectedSize) - { - pg_log_fatal("unexpected file size for \"%s\": %lld instead of %lld", - xlogfname, (long long int) stat_buf.st_size, - (long long int) expectedSize); - exit(1); - } + pg_fatal("unexpected file size for \"%s\": %lld instead of %lld", + xlogfname, (long long int) stat_buf.st_size, + (long long int) expectedSize); else { int xlogfd = open(xlogpath, O_RDONLY | PG_BINARY, 0); if (xlogfd < 0) - { - pg_log_fatal("could not open file \"%s\" restored from archive: %m", - xlogpath); - exit(1); - } + pg_fatal("could not open file \"%s\" restored from archive: %m", + xlogpath); else return xlogfd; } @@ -93,11 +84,8 @@ RestoreArchivedFile(const char *path, const char *xlogfname, else { if (errno != ENOENT) - { - pg_log_fatal("could not stat file \"%s\": %m", - xlogpath); - exit(1); - } + pg_fatal("could not stat file \"%s\": %m", + xlogpath); } } @@ -108,11 +96,8 @@ RestoreArchivedFile(const char *path, const char *xlogfname, * fatal too. */ if (wait_result_is_any_signal(rc, true)) - { - pg_log_fatal("restore_command failed: %s", - wait_result_to_str(rc)); - exit(1); - } + pg_fatal("restore_command failed: %s", + wait_result_to_str(rc)); /* * The file is not available, so just let the caller decide what to do -- cgit v1.2.3