Hi all, While looking at another patch for slot.c, I have noticed what looks like incorrect use of errcode_for_file_access: - errcode_for_file_access() is used with rmtree(), which makes no sense as this comes from common/rmtree.c, and a warning already shows up using %m. - ERRCODE_DATA_CORRUPTED is not used to mention corrupted data, and instead errcode_for_file_access() gets called.
Wouldn't something like the attached provide more adapted error handling? That's mostly error handling beautification, so I would be incline to just fix HEAD. (I have noticed some inconsistent error string format in autoprewarm.c on the way.) Thoughts? -- Michael
diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index cc5e2dd89c..03bf90ce2d 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -641,7 +641,7 @@ apw_dump_now(bool is_bgworker, bool dump_unlogged)
errno = save_errno;
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not write to file \"%s\" : %m",
+ errmsg("could not write to file \"%s\": %m",
transient_dump_file_path)));
}
@@ -664,7 +664,7 @@ apw_dump_now(bool is_bgworker, bool dump_unlogged)
errno = save_errno;
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not write to file \"%s\" : %m",
+ errmsg("could not write to file \"%s\": %m",
transient_dump_file_path)));
}
}
@@ -684,7 +684,7 @@ apw_dump_now(bool is_bgworker, bool dump_unlogged)
errno = save_errno;
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not close file \"%s\" : %m",
+ errmsg("could not close file \"%s\": %m",
transient_dump_file_path)));
}
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index cb781e6e9a..800ca14488 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -628,8 +628,7 @@ ReplicationSlotDropPtr(ReplicationSlot *slot)
*/
if (!rmtree(tmppath, true))
ereport(WARNING,
- (errcode_for_file_access(),
- errmsg("could not remove directory \"%s\"", tmppath)));
+ (errmsg("could not remove directory \"%s\"", tmppath)));
/*
* We release this at the very end, so that nobody starts trying to create
@@ -1132,8 +1131,8 @@ StartupReplicationSlots(void)
if (!rmtree(path, true))
{
ereport(WARNING,
- (errcode_for_file_access(),
- errmsg("could not remove directory \"%s\"", path)));
+ (errmsg("could not remove directory \"%s\"",
+ path)));
continue;
}
fsync_fname("pg_replslot", true);
@@ -1432,21 +1431,21 @@ RestoreSlotFromDisk(const char *name)
/* verify magic */
if (cp.magic != SLOT_MAGIC)
ereport(PANIC,
- (errcode_for_file_access(),
+ (errcode(ERRCODE_DATA_CORRUPTED),
errmsg("replication slot file \"%s\" has wrong magic number: %u instead of %u",
path, cp.magic, SLOT_MAGIC)));
/* verify version */
if (cp.version != SLOT_VERSION)
ereport(PANIC,
- (errcode_for_file_access(),
+ (errcode(ERRCODE_DATA_CORRUPTED),
errmsg("replication slot file \"%s\" has unsupported version %u",
path, cp.version)));
/* boundary check on length */
if (cp.length != ReplicationSlotOnDiskV2Size)
ereport(PANIC,
- (errcode_for_file_access(),
+ (errcode(ERRCODE_DATA_CORRUPTED),
errmsg("replication slot file \"%s\" has corrupted length %u",
path, cp.length)));
@@ -1496,8 +1495,8 @@ RestoreSlotFromDisk(const char *name)
if (!rmtree(slotdir, true))
{
ereport(WARNING,
- (errcode_for_file_access(),
- errmsg("could not remove directory \"%s\"", slotdir)));
+ (errmsg("could not remove directory \"%s\"",
+ slotdir)));
}
fsync_fname("pg_replslot", true);
return;
signature.asc
Description: PGP signature
