aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_backup_custom.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/pg_dump/pg_backup_custom.c
parent5c431c7fb327e1abc70b7a197650f8d45fd5bede (diff)
downloadpostgresql-9a374b77fb53e4cfbca121e4fa278a7d71bde7c4.tar.gz
postgresql-9a374b77fb53e4cfbca121e4fa278a7d71bde7c4.zip
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/pg_dump/pg_backup_custom.c')
-rw-r--r--src/bin/pg_dump/pg_backup_custom.c72
1 files changed, 36 insertions, 36 deletions
diff --git a/src/bin/pg_dump/pg_backup_custom.c b/src/bin/pg_dump/pg_backup_custom.c
index 77d402c323e..c3b9c365d5c 100644
--- a/src/bin/pg_dump/pg_backup_custom.c
+++ b/src/bin/pg_dump/pg_backup_custom.c
@@ -153,13 +153,13 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
{
AH->FH = fopen(AH->fSpec, PG_BINARY_W);
if (!AH->FH)
- fatal("could not open output file \"%s\": %m", AH->fSpec);
+ pg_fatal("could not open output file \"%s\": %m", AH->fSpec);
}
else
{
AH->FH = stdout;
if (!AH->FH)
- fatal("could not open output file: %m");
+ pg_fatal("could not open output file: %m");
}
ctx->hasSeek = checkSeek(AH->FH);
@@ -170,13 +170,13 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
{
AH->FH = fopen(AH->fSpec, PG_BINARY_R);
if (!AH->FH)
- fatal("could not open input file \"%s\": %m", AH->fSpec);
+ pg_fatal("could not open input file \"%s\": %m", AH->fSpec);
}
else
{
AH->FH = stdin;
if (!AH->FH)
- fatal("could not open input file: %m");
+ pg_fatal("could not open input file: %m");
}
ctx->hasSeek = checkSeek(AH->FH);
@@ -373,7 +373,7 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
lclContext *ctx = (lclContext *) AH->formatData;
if (oid == 0)
- fatal("invalid OID for large object");
+ pg_fatal("invalid OID for large object");
WriteInt(AH, oid);
@@ -436,7 +436,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te)
if (ctx->hasSeek)
{
if (fseeko(AH->FH, ctx->lastFilePos, SEEK_SET) != 0)
- fatal("error during file seek: %m");
+ pg_fatal("error during file seek: %m");
}
for (;;)
@@ -492,8 +492,8 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te)
break;
default: /* Always have a default */
- fatal("unrecognized data block type (%d) while searching archive",
- blkType);
+ pg_fatal("unrecognized data block type (%d) while searching archive",
+ blkType);
break;
}
}
@@ -502,7 +502,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te)
{
/* We can just seek to the place we need to be. */
if (fseeko(AH->FH, tctx->dataPos, SEEK_SET) != 0)
- fatal("error during file seek: %m");
+ pg_fatal("error during file seek: %m");
_readBlockHeader(AH, &blkType, &id);
}
@@ -514,20 +514,20 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te)
if (blkType == EOF)
{
if (!ctx->hasSeek)
- fatal("could not find block ID %d in archive -- "
- "possibly due to out-of-order restore request, "
- "which cannot be handled due to non-seekable input file",
- te->dumpId);
+ pg_fatal("could not find block ID %d in archive -- "
+ "possibly due to out-of-order restore request, "
+ "which cannot be handled due to non-seekable input file",
+ te->dumpId);
else
- fatal("could not find block ID %d in archive -- "
- "possibly corrupt archive",
- te->dumpId);
+ pg_fatal("could not find block ID %d in archive -- "
+ "possibly corrupt archive",
+ te->dumpId);
}
/* Are we sane? */
if (id != te->dumpId)
- fatal("found unexpected block ID (%d) when reading data -- expected %d",
- id, te->dumpId);
+ pg_fatal("found unexpected block ID (%d) when reading data -- expected %d",
+ id, te->dumpId);
switch (blkType)
{
@@ -540,8 +540,8 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te)
break;
default: /* Always have a default */
- fatal("unrecognized data block type %d while restoring archive",
- blkType);
+ pg_fatal("unrecognized data block type %d while restoring archive",
+ blkType);
break;
}
@@ -626,7 +626,7 @@ _skipData(ArchiveHandle *AH)
if (ctx->hasSeek)
{
if (fseeko(AH->FH, blkLen, SEEK_CUR) != 0)
- fatal("error during file seek: %m");
+ pg_fatal("error during file seek: %m");
}
else
{
@@ -640,9 +640,9 @@ _skipData(ArchiveHandle *AH)
if (fread(buf, 1, blkLen, AH->FH) != blkLen)
{
if (feof(AH->FH))
- fatal("could not read from input file: end of file");
+ pg_fatal("could not read from input file: end of file");
else
- fatal("could not read from input file: %m");
+ pg_fatal("could not read from input file: %m");
}
}
@@ -743,7 +743,7 @@ _CloseArchive(ArchiveHandle *AH)
/* Remember TOC's seek position for use below */
tpos = ftello(AH->FH);
if (tpos < 0 && ctx->hasSeek)
- fatal("could not determine seek position in archive file: %m");
+ pg_fatal("could not determine seek position in archive file: %m");
WriteToc(AH);
WriteDataChunks(AH, NULL);
@@ -759,7 +759,7 @@ _CloseArchive(ArchiveHandle *AH)
}
if (fclose(AH->FH) != 0)
- fatal("could not close archive file: %m");
+ pg_fatal("could not close archive file: %m");
/* Sync the output file if one is defined */
if (AH->dosync && AH->mode == archModeWrite && AH->fSpec)
@@ -782,32 +782,32 @@ _ReopenArchive(ArchiveHandle *AH)
pgoff_t tpos;
if (AH->mode == archModeWrite)
- fatal("can only reopen input archives");
+ pg_fatal("can only reopen input archives");
/*
* These two cases are user-facing errors since they represent unsupported
* (but not invalid) use-cases. Word the error messages appropriately.
*/
if (AH->fSpec == NULL || strcmp(AH->fSpec, "") == 0)
- fatal("parallel restore from standard input is not supported");
+ pg_fatal("parallel restore from standard input is not supported");
if (!ctx->hasSeek)
- fatal("parallel restore from non-seekable file is not supported");
+ pg_fatal("parallel restore from non-seekable file is not supported");
tpos = ftello(AH->FH);
if (tpos < 0)
- fatal("could not determine seek position in archive file: %m");
+ pg_fatal("could not determine seek position in archive file: %m");
#ifndef WIN32
if (fclose(AH->FH) != 0)
- fatal("could not close archive file: %m");
+ pg_fatal("could not close archive file: %m");
#endif
AH->FH = fopen(AH->fSpec, PG_BINARY_R);
if (!AH->FH)
- fatal("could not open input file \"%s\": %m", AH->fSpec);
+ pg_fatal("could not open input file \"%s\": %m", AH->fSpec);
if (fseeko(AH->FH, tpos, SEEK_SET) != 0)
- fatal("could not set seek position in archive file: %m");
+ pg_fatal("could not set seek position in archive file: %m");
}
/*
@@ -862,7 +862,7 @@ _PrepParallelRestore(ArchiveHandle *AH)
pgoff_t endpos;
if (fseeko(AH->FH, 0, SEEK_END) != 0)
- fatal("error during file seek: %m");
+ pg_fatal("error during file seek: %m");
endpos = ftello(AH->FH);
if (endpos > prev_tctx->dataPos)
prev_te->dataLength = endpos - prev_tctx->dataPos;
@@ -886,7 +886,7 @@ _Clone(ArchiveHandle *AH)
/* sanity check, shouldn't happen */
if (ctx->cs != NULL)
- fatal("compressor active");
+ pg_fatal("compressor active");
/*
* We intentionally do not clone TOC-entry-local state: it's useful to
@@ -940,7 +940,7 @@ _getFilePos(ArchiveHandle *AH, lclContext *ctx)
{
/* Not expected if we found we can seek. */
if (ctx->hasSeek)
- fatal("could not determine seek position in archive file: %m");
+ pg_fatal("could not determine seek position in archive file: %m");
}
return pos;
}
@@ -956,7 +956,7 @@ _readBlockHeader(ArchiveHandle *AH, int *type, int *id)
int byt;
/*
- * Note: if we are at EOF with a pre-1.3 input file, we'll fatal() inside
+ * Note: if we are at EOF with a pre-1.3 input file, we'll pg_fatal() inside
* ReadInt rather than returning EOF. It doesn't seem worth jumping
* through hoops to deal with that case better, because no such files are
* likely to exist in the wild: only some 7.1 development versions of