diff --git a/src/backend/utils/adt/jsonpath.c b/src/backend/utils/adt/jsonpath.c index fb9d85213d4..ddf02e4d749 100644 --- a/src/backend/utils/adt/jsonpath.c +++ b/src/backend/utils/adt/jsonpath.c @@ -416,7 +416,9 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item, case jpiKeyValue: break; default: - elog(ERROR, "unrecognized jsonpath item type: %d", item->type); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("unrecognized jsonpath item type: %d", item->type))); } if (item->next) @@ -693,7 +695,9 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey, appendBinaryStringInfo(buf, ".keyvalue()", 11); break; default: - elog(ERROR, "unrecognized jsonpath item type: %d", v->type); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("unrecognized jsonpath item type: %d", v->type))); } if (jspGetNext(v, &elem)) @@ -752,7 +756,9 @@ jspOperationName(JsonPathItemType type) case jpiCeiling: return "ceiling"; default: - elog(ERROR, "unrecognized jsonpath item type: %d", type); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("unrecognized jsonpath item type: %d", type))); return NULL; } } @@ -898,7 +904,9 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos) read_int32(v->content.anybounds.last, base, pos); break; default: - elog(ERROR, "unrecognized jsonpath item type: %d", v->type); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("unrecognized jsonpath item type: %d", v->type))); } } diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c index 074cea24ae3..e0b6c941fcd 100644 --- a/src/backend/utils/adt/jsonpath_exec.c +++ b/src/backend/utils/adt/jsonpath_exec.c @@ -350,7 +350,7 @@ jsonb_path_match(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_SINGLETON_JSON_ITEM_REQUIRED), errmsg(ERRMSG_SINGLETON_JSON_ITEM_REQUIRED), - errdetail("expression should return a singleton boolean"))); + errdetail("Singleton boolean result is expected."))); PG_RETURN_NULL(); } @@ -497,8 +497,9 @@ executeJsonPath(JsonPath *path, Jsonb *vars, Jsonb *json, bool throwErrors, { ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("jsonb containing jsonpath variables " - "is not an object"))); + errmsg("\"vars\" argument is not an object"), + errdetail("Jsonpath parameters should be encoded as key-value" + "pairs of \"vars\" object."))); } cxt.vars = vars; @@ -623,7 +624,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, ereport(ERROR, (errcode(ERRCODE_JSON_MEMBER_NOT_FOUND), \ errmsg(ERRMSG_JSON_MEMBER_NOT_FOUND), - errdetail("JSON object does not contain key %s", + errdetail("JSON object does not contain key %s.", keybuf.data))); } } @@ -635,8 +636,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_JSON_MEMBER_NOT_FOUND), errmsg(ERRMSG_JSON_MEMBER_NOT_FOUND), - errdetail("jsonpath member accessor can " - "only be applied to an object")))); + errdetail("Jsonpath member accessor can " + "only be applied to an object.")))); } break; @@ -666,8 +667,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_JSON_ARRAY_NOT_FOUND), errmsg(ERRMSG_JSON_ARRAY_NOT_FOUND), - errdetail("jsonpath wildcard array accessor " - "can only be applied to an array")))); + errdetail("Jsonpath wildcard array accessor " + "can only be applied to an array.")))); break; case jpiIndexArray: @@ -716,8 +717,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_INVALID_JSON_SUBSCRIPT), errmsg(ERRMSG_INVALID_JSON_SUBSCRIPT), - errdetail("jsonpath array subscript is " - "out of bounds")))); + errdetail("Jsonpath array subscript is " + "out of bounds.")))); if (index_from < 0) index_from = 0; @@ -775,8 +776,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_JSON_ARRAY_NOT_FOUND), errmsg(ERRMSG_JSON_ARRAY_NOT_FOUND), - errdetail("jsonpath array accessor can " - "only be applied to an array")))); + errdetail("Jsonpath array accessor can " + "only be applied to an array.")))); } break; @@ -788,8 +789,13 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, bool hasNext = jspGetNext(jsp, &elem); if (cxt->innermostArraySize < 0) - elog(ERROR, "evaluating jsonpath LAST outside of " - "array subscript"); + { + /* should be catched during jsonpath construction */ + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("evaluating jsonpath LAST outside of " + "array subscript"))); + } if (!hasNext && !found) { @@ -817,7 +823,10 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, bool hasNext = jspGetNext(jsp, &elem); if (jb->type != jbvBinary) - elog(ERROR, "invalid jsonb object type: %d", jb->type); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("invalid jsonb object type: %d", + jb->type))); return executeAnyItem (cxt, hasNext ? &elem : NULL, @@ -832,8 +841,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_JSON_OBJECT_NOT_FOUND), errmsg(ERRMSG_JSON_OBJECT_NOT_FOUND), - errdetail("jsonpath wildcard member accessor " - "can only be applied to an object")))); + errdetail("Jsonpath wildcard member accessor " + "can only be applied to an object.")))); } break; @@ -964,8 +973,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_JSON_ARRAY_NOT_FOUND), errmsg(ERRMSG_JSON_ARRAY_NOT_FOUND), - errdetail("jsonpath item method .%s() " - "can only be applied to an array", + errdetail("Jsonpath item method .%s() " + "can only be applied to an array.", jspOperationName(jsp->type))))); break; } @@ -1020,9 +1029,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_JSON_ITEM), errmsg(ERRMSG_NON_NUMERIC_JSON_ITEM), - errdetail("jsonpath item method .%s() " + errdetail("Jsonpath item method .%s() " "can only be applied to " - "a numeric value", + "a numeric value.", jspOperationName(jsp->type))))); res = jperOk; } @@ -1044,8 +1053,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_JSON_ITEM), errmsg(ERRMSG_NON_NUMERIC_JSON_ITEM), - errdetail("jsonpath item method .%s() can " - "only be applied to a numeric value", + errdetail("Jsonpath item method .%s() can " + "only be applied to a numeric value.", jspOperationName(jsp->type))))); jb = &jbv; @@ -1059,9 +1068,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_JSON_ITEM), errmsg(ERRMSG_NON_NUMERIC_JSON_ITEM), - errdetail("jsonpath item method .%s() " + errdetail("Jsonpath item method .%s() " "can only be applied to a " - "string or numeric value", + "string or numeric value.", jspOperationName(jsp->type))))); res = executeNextItem(cxt, jsp, NULL, jb, found, true); @@ -1075,7 +1084,10 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, return executeKeyValueMethod(cxt, jsp, jb, found); default: - elog(ERROR, "unrecognized jsonpath item type: %d", jsp->type); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("unrecognized jsonpath item type: %d", + jsp->type))); } return res; @@ -1092,7 +1104,10 @@ executeItemUnwrapTargetArray(JsonPathExecContext *cxt, JsonPathItem *jsp, if (jb->type != jbvBinary) { Assert(jb->type != jbvArray); - elog(ERROR, "invalid jsonb array value type: %d", jb->type); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("invalid jsonb array value type: %d", + jb->type))); } return executeAnyItem @@ -1197,7 +1212,9 @@ executeBoolItem(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonPathBool res2; if (!canHaveNext && jspHasNext(jsp)) - elog(ERROR, "boolean jsonpath item cannot have next item"); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("boolean jsonpath item cannot have next item"))); switch (jsp->type) { @@ -1311,7 +1328,10 @@ executeBoolItem(JsonPathExecContext *cxt, JsonPathItem *jsp, } default: - elog(ERROR, "invalid boolean jsonpath item type: %d", jsp->type); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("invalid boolean jsonpath item type: %d", + jsp->type))); return jpbUnknown; } } @@ -1546,8 +1566,8 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_SINGLETON_JSON_ITEM_REQUIRED), errmsg(ERRMSG_SINGLETON_JSON_ITEM_REQUIRED), - errdetail("left operand of binary jsonpath operator %s " - "is not a singleton numeric value", + errdetail("Left operand of binary jsonpath operator %s " + "is not a singleton numeric value.", jspOperationName(jsp->type))))); if (JsonValueListLength(&rseq) != 1 || @@ -1555,8 +1575,8 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_SINGLETON_JSON_ITEM_REQUIRED), errmsg(ERRMSG_SINGLETON_JSON_ITEM_REQUIRED), - errdetail("right operand of binary jsonpath operator %s " - "is not a singleton numeric value", + errdetail("Right operand of binary jsonpath operator %s " + "is not a singleton numeric value.", jspOperationName(jsp->type))))); if (jspThrowErrors(cxt)) @@ -1625,8 +1645,8 @@ executeUnaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_JSON_NUMBER_NOT_FOUND), errmsg(ERRMSG_JSON_NUMBER_NOT_FOUND), - errdetail("operand of unary jsonpath operator %s " - "is not a numeric value", + errdetail("Operand of unary jsonpath operator %s " + "is not a numeric value.", jspOperationName(jsp->type))))); } @@ -1738,8 +1758,8 @@ executeNumericItemMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_JSON_ITEM), errmsg(ERRMSG_NON_NUMERIC_JSON_ITEM), - errdetail("jsonpath item method .%s() can only " - "be applied to a numeric value", + errdetail("Jsonpath item method .%s() can only " + "be applied to a numeric value.", jspOperationName(jsp->type))))); datum = NumericGetDatum(jb->val.numeric); @@ -1800,8 +1820,8 @@ executeKeyValueMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_JSON_OBJECT_NOT_FOUND), errmsg(ERRMSG_JSON_OBJECT_NOT_FOUND), - errdetail("jsonpath item method .%s() " - "can only be applied to an object", + errdetail("Jsonpath item method .%s() " + "can only be applied to an object.", jspOperationName(jsp->type))))); jbc = jb->val.binary.data; @@ -1945,7 +1965,10 @@ getJsonPathItem(JsonPathExecContext *cxt, JsonPathItem *item, getJsonPathVariable(cxt, item, cxt->vars, value); return; default: - elog(ERROR, "unexpected jsonpath item type"); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("invalid scalar jsonpath item type: %d", + item->type))); } } @@ -2073,7 +2096,9 @@ compareItems(int32 op, JsonbValue *jb1, JsonbValue *jb2) return jpbUnknown; /* non-scalars are not comparable */ default: - elog(ERROR, "invalid jsonb value type %d", jb1->type); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("invalid jsonb value type %d", jb1->type))); } switch (op) @@ -2097,7 +2122,9 @@ compareItems(int32 op, JsonbValue *jb1, JsonbValue *jb2) res = (cmp >= 0); break; default: - elog(ERROR, "unrecognized jsonpath operation: %d", op); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("unrecognized jsonpath operation: %d", op))); return jpbUnknown; } @@ -2145,8 +2172,8 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_INVALID_JSON_SUBSCRIPT), errmsg(ERRMSG_INVALID_JSON_SUBSCRIPT), - errdetail("jsonpath array subscript is not a " - "singleton numeric value")))); + errdetail("Jsonpath array subscript is not a " + "singleton numeric value.")))); numeric_index = DirectFunctionCall2(numeric_trunc, NumericGetDatum(jbv->val.numeric), @@ -2159,8 +2186,8 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb, RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_INVALID_JSON_SUBSCRIPT), errmsg(ERRMSG_INVALID_JSON_SUBSCRIPT), - errdetail("jsonpath array subscript is " - "out of integer range")))); + errdetail("Jsonpath array subscript is " + "out of integer range.")))); return jperOk; } @@ -2293,7 +2320,10 @@ JsonbType(JsonbValue *jb) else if (JsonContainerIsArray(jbc)) type = jbvArray; else - elog(ERROR, "invalid jsonb container type: 0x%08x", jbc->header); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("invalid jsonb container type: 0x%08x", + jbc->header))); } return type; diff --git a/src/backend/utils/adt/jsonpath_scan.l b/src/backend/utils/adt/jsonpath_scan.l index 72bb5e3937b..b50fe8f333b 100644 --- a/src/backend/utils/adt/jsonpath_scan.l +++ b/src/backend/utils/adt/jsonpath_scan.l @@ -495,7 +495,7 @@ hexval(char c) return c - 'a' + 0xA; if (c >= 'A' && c <= 'F') return c - 'A' + 0xA; - elog(ERROR, "invalid hexadecimal digit"); + jsonpath_yyerror(NULL, "invalid hexadecimal digit"); return 0; /* not reached */ }