Improve error message on snapshot import in snapmgr.c
authorMichael Paquier <[email protected]>
Thu, 14 Sep 2023 01:30:08 +0000 (10:30 +0900)
committerMichael Paquier <[email protected]>
Thu, 14 Sep 2023 01:30:08 +0000 (10:30 +0900)
When a snapshot file fails to be read in ImportSnapshot(), it would
issue an ERROR as "invalid snapshot identifier" when opening a stream
for it in read-only mode.  This error message is reworded to be the same
as all the other messages used in this case on failure, which is useful
when debugging this area.

Thinko introduced by bb446b689b66 where snapshot imports have been
added.  A backpatch down to 11 is done as this can improve any work
related to snapshot imports in older branches.

Author: Bharath Rupireddy
Reviewed-by: Daniel Gustafsson
Discussion: https://postgr.es/m/CALj2ACWmr=3KdxDkm8h7Zn1XxBoF6hdzq8WQyMn2y1OL5RYFrg@mail.gmail.com
Backpatch-through: 11

src/backend/utils/time/snapmgr.c

index b20440ee21ff8ad836aa8ef72aa0d18fd3dd85f3..65230811c022c4f2a34d0938bd1ff2e50f78ce32 100644 (file)
@@ -1391,8 +1391,9 @@ ImportSnapshot(const char *idstr)
    f = AllocateFile(path, PG_BINARY_R);
    if (!f)
        ereport(ERROR,
-               (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                errmsg("invalid snapshot identifier: \"%s\"", idstr)));
+               (errcode_for_file_access(),
+                errmsg("could not open file \"%s\" for reading: %m",
+                       path)));
 
    /* get the size of the file so that we know how much memory we need */
    if (fstat(fileno(f), &stat_buf))