Improve checkStringLen() error message
authorPeter Geoghegan <pg@heroku.com>
Sun, 16 Mar 2014 07:06:28 +0000 (00:06 -0700)
committerPeter Geoghegan <pg@heroku.com>
Sun, 16 Mar 2014 07:06:28 +0000 (00:06 -0700)
src/backend/utils/adt/jsonb.c

index a4b7a2c4a64b00a133a8cc90923e3d173c9a1c83..fbe949370c8c3e3db268746f64dc158798762a9a 100644 (file)
@@ -198,8 +198,11 @@ checkStringLen(size_t len)
 {
    if (len > JENTRY_POSMASK)
        ereport(ERROR,
-               (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
-                errmsg("string too long for jsonb string")));
+               (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+                errmsg("string too long to represent as jsonb string"),
+                errdetail("Due to an implementation restriction, jsonb strings cannot exceed %d bytes.",
+                          JENTRY_POSMASK)));
+
    return len;
 }
 
@@ -297,10 +300,14 @@ jsonb_in_scalar(void *state, char *token, JsonTokenType tokentype)
            v.estSize += v.string.len;
            break;
        case JSON_TOKEN_NUMBER:
+           /*
+            * No need to check size of numeric values, because maximum numeric
+            * size is well in excess of the restriction we separately impose
+            * of the size of JsonbValues
+            */
            v.type = jbvNumeric;
            v.numeric = DatumGetNumeric(DirectFunctionCall3(numeric_in, CStringGetDatum(token), 0, -1));
-
-           v.estSize += VARSIZE_ANY(v.numeric) +sizeof(JEntry) /* alignment */ ;
+           v.estSize += VARSIZE_ANY(v.numeric) + sizeof(JEntry) /* alignment */ ;
            break;
        case JSON_TOKEN_TRUE:
            v.type = jbvBool;