Improve enlargeStringInfo's ERROR message
authorDavid Rowley <[email protected]>
Mon, 1 Jul 2024 00:11:10 +0000 (12:11 +1200)
committerDavid Rowley <[email protected]>
Mon, 1 Jul 2024 00:11:10 +0000 (12:11 +1200)
Until now, when an enlargeStringInfo() call would cause the StringInfo to
exceed its maximum size, we reported an "out of memory" error.  This is
misleading as it's no such thing.

Here we remove the "out of memory" text and replace it with something
more relevant to better indicate that it's a program limitation that's
been reached.

Reported-by: Michael Banck
Reviewed-by: Daniel Gustafsson, Tom Lane
Discussion: https://postgr.es/m/18484-3e357ade5fe50e61@postgresql.org

src/common/stringinfo.c

index ec5fc2422d81cf5431759f6da014308fbe12af10..eb9d6502fc89ab4c839676d75ce86773effb5461 100644 (file)
@@ -311,13 +311,13 @@ enlargeStringInfo(StringInfo str, int needed)
 #ifndef FRONTEND
        ereport(ERROR,
                (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
-                errmsg("out of memory"),
+                errmsg("string buffer exceeds maximum allowed length (%zu bytes)", MaxAllocSize),
                 errdetail("Cannot enlarge string buffer containing %d bytes by %d more bytes.",
                           str->len, needed)));
 #else
        fprintf(stderr,
-               _("out of memory\n\nCannot enlarge string buffer containing %d bytes by %d more bytes.\n"),
-               str->len, needed);
+               _("string buffer exceeds maximum allowed length (%zu bytes)\n\nCannot enlarge string buffer containing %d bytes by %d more bytes.\n"),
+               MaxAllocSize, str->len, needed);
        exit(EXIT_FAILURE);
 #endif
    }