Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 62b7a9a

Browse files
committed
Refactor some SQL/JSON error messages
Turn type names into "%s" specifiers to 1) avoid getting them translated and 2) reduce the total number of messages.
1 parent 7bc9a8b commit 62b7a9a

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/backend/utils/adt/jsonpath_exec.c

+21-20
Original file line numberDiff line numberDiff line change
@@ -1162,8 +1162,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
11621162
if (escontext.error_occurred)
11631163
RETURN_ERROR(ereport(ERROR,
11641164
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
1165-
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type double precision",
1166-
tmp, jspOperationName(jsp->type)))));
1165+
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
1166+
tmp, jspOperationName(jsp->type), "double precision"))));
11671167
if (isinf(val) || isnan(val))
11681168
RETURN_ERROR(ereport(ERROR,
11691169
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
@@ -1188,8 +1188,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
11881188
if (escontext.error_occurred)
11891189
RETURN_ERROR(ereport(ERROR,
11901190
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
1191-
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type double precision",
1192-
tmp, jspOperationName(jsp->type)))));
1191+
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
1192+
tmp, jspOperationName(jsp->type), "double precision"))));
11931193
if (isinf(val) || isnan(val))
11941194
RETURN_ERROR(ereport(ERROR,
11951195
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
@@ -1276,10 +1276,11 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
12761276
if (have_error)
12771277
RETURN_ERROR(ereport(ERROR,
12781278
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
1279-
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type bigint",
1279+
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
12801280
DatumGetCString(DirectFunctionCall1(numeric_out,
12811281
NumericGetDatum(jb->val.numeric))),
1282-
jspOperationName(jsp->type)))));
1282+
jspOperationName(jsp->type),
1283+
"bigint"))));
12831284

12841285
datum = Int64GetDatum(val);
12851286
res = jperOk;
@@ -1300,8 +1301,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
13001301
if (!noerr || escontext.error_occurred)
13011302
RETURN_ERROR(ereport(ERROR,
13021303
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
1303-
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type bigint",
1304-
tmp, jspOperationName(jsp->type)))));
1304+
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
1305+
tmp, jspOperationName(jsp->type), "bigint"))));
13051306
res = jperOk;
13061307
}
13071308

@@ -1352,8 +1353,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
13521353
if (!noerr || escontext.error_occurred)
13531354
RETURN_ERROR(ereport(ERROR,
13541355
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
1355-
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type boolean",
1356-
tmp, jspOperationName(jsp->type)))));
1356+
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
1357+
tmp, jspOperationName(jsp->type), "boolean"))));
13571358

13581359
ival = DatumGetInt32(datum);
13591360
if (ival == 0)
@@ -1372,8 +1373,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
13721373
if (!parse_bool(tmp, &bval))
13731374
RETURN_ERROR(ereport(ERROR,
13741375
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
1375-
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type boolean",
1376-
tmp, jspOperationName(jsp->type)))));
1376+
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
1377+
tmp, jspOperationName(jsp->type), "boolean"))));
13771378

13781379
res = jperOk;
13791380
}
@@ -1434,8 +1435,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
14341435
if (!noerr || escontext.error_occurred)
14351436
RETURN_ERROR(ereport(ERROR,
14361437
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
1437-
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type numeric",
1438-
numstr, jspOperationName(jsp->type)))));
1438+
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
1439+
numstr, jspOperationName(jsp->type), "numeric"))));
14391440

14401441
num = DatumGetNumeric(datum);
14411442
if (numeric_is_nan(num) || numeric_is_inf(num))
@@ -1523,8 +1524,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
15231524
if (!noerr || escontext.error_occurred)
15241525
RETURN_ERROR(ereport(ERROR,
15251526
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
1526-
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type numeric",
1527-
numstr, jspOperationName(jsp->type)))));
1527+
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
1528+
numstr, jspOperationName(jsp->type), "numeric"))));
15281529

15291530
num = DatumGetNumeric(numdatum);
15301531
pfree(arrtypmod);
@@ -1556,10 +1557,10 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
15561557
if (have_error)
15571558
RETURN_ERROR(ereport(ERROR,
15581559
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
1559-
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type integer",
1560+
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
15601561
DatumGetCString(DirectFunctionCall1(numeric_out,
15611562
NumericGetDatum(jb->val.numeric))),
1562-
jspOperationName(jsp->type)))));
1563+
jspOperationName(jsp->type), "integer"))));
15631564

15641565
datum = Int32GetDatum(val);
15651566
res = jperOk;
@@ -1580,8 +1581,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
15801581
if (!noerr || escontext.error_occurred)
15811582
RETURN_ERROR(ereport(ERROR,
15821583
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
1583-
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type integer",
1584-
tmp, jspOperationName(jsp->type)))));
1584+
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
1585+
tmp, jspOperationName(jsp->type), "integer"))));
15851586
res = jperOk;
15861587
}
15871588

0 commit comments

Comments
 (0)