]> granicus.if.org Git - postgresql/commitdiff
Fix erroneous error reports in snapbuild.c.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 12 Feb 2019 06:12:52 +0000 (01:12 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 12 Feb 2019 06:12:52 +0000 (01:12 -0500)
It's pretty unhelpful to report the wrong file name in a complaint
about syscall failure, but SnapBuildSerialize managed to do that twice
in a span of 50 lines.  Also fix half a dozen missing or poorly-chosen
errcode assignments; that's mostly cosmetic, but still wrong.

Noted while studying recent failures on buildfarm member nightjar.
I'm not sure whether those reports are actually giving the wrong
filename, because there are two places here with identically
spelled error messages.  The other one is specifically coded not
to report ENOENT, but if it's this one, how could we be getting
ENOENT from open() with O_CREAT?  Need to sit back and await results.

However, these ereports are clearly broken from birth, so back-patch.

src/backend/replication/logical/snapbuild.c

index 8ce99f4af969e34bb4ec44c46bf30a52b5120f9d..7fb7057fa32baf0e4310710e790dcd79e5234ffd 100644 (file)
@@ -1483,7 +1483,8 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
 
        if (ret != 0 && errno != ENOENT)
                ereport(ERROR,
-                               (errmsg("could not stat file \"%s\": %m", path)));
+                               (errcode_for_file_access(),
+                                errmsg("could not stat file \"%s\": %m", path)));
 
        else if (ret == 0)
        {
@@ -1525,7 +1526,7 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
        if (unlink(tmppath) != 0 && errno != ENOENT)
                ereport(ERROR,
                                (errcode_for_file_access(),
-                                errmsg("could not remove file \"%s\": %m", path)));
+                                errmsg("could not remove file \"%s\": %m", tmppath)));
 
        needed_length = sizeof(SnapBuildOnDisk) +
                sizeof(TransactionId) * builder->committed.xcnt;
@@ -1569,7 +1570,8 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
                                                   S_IRUSR | S_IWUSR);
        if (fd < 0)
                ereport(ERROR,
-                               (errmsg("could not open file \"%s\": %m", path)));
+                               (errcode_for_file_access(),
+                                errmsg("could not open file \"%s\": %m", tmppath)));
 
        errno = 0;
        if ((write(fd, ondisk, needed_length)) != needed_length)
@@ -1695,12 +1697,14 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
 
        if (ondisk.magic != SNAPBUILD_MAGIC)
                ereport(ERROR,
-                               (errmsg("snapbuild state file \"%s\" has wrong magic %u instead of %u",
+                               (errcode(ERRCODE_DATA_CORRUPTED),
+                                errmsg("snapbuild state file \"%s\" has wrong magic %u instead of %u",
                                                path, ondisk.magic, SNAPBUILD_MAGIC)));
 
        if (ondisk.version != SNAPBUILD_VERSION)
                ereport(ERROR,
-                               (errmsg("snapbuild state file \"%s\" has unsupported version %u instead of %u",
+                               (errcode(ERRCODE_DATA_CORRUPTED),
+                                errmsg("snapbuild state file \"%s\" has unsupported version %u instead of %u",
                                                path, ondisk.version, SNAPBUILD_VERSION)));
 
        INIT_CRC32(checksum);
@@ -1765,7 +1769,7 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
        /* verify checksum of what we've read */
        if (!EQ_CRC32(checksum, ondisk.checksum))
                ereport(ERROR,
-                               (errcode_for_file_access(),
+                               (errcode(ERRCODE_DATA_CORRUPTED),
                                 errmsg("snapbuild state file %s: checksum mismatch, is %u, should be %u",
                                                path, checksum, ondisk.checksum)));