From c60c9badba9b4db3155eef081ae0b923f983168c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 11 Dec 2022 11:28:15 -0500 Subject: Convert json_in and jsonb_in to report errors softly. This requires a bit of further infrastructure-extension to allow trapping errors reported by numeric_in and pg_unicode_to_server, but otherwise it's pretty straightforward. In the case of jsonb_in, we are only capturing errors reported during the initial "parse" phase. The value-construction phase (JsonbValueToJsonb) can also throw errors if assorted implementation limits are exceeded. We should improve that, but it seems like a separable project. Andrew Dunstan and Tom Lane Discussion: https://postgr.es/m/3bac9841-fe07-713d-fa42-606c225567d6@dunslane.net --- src/backend/utils/adt/json.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/backend/utils/adt/json.c') diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c index fee2ffb55c8..e6896eccfe9 100644 --- a/src/backend/utils/adt/json.c +++ b/src/backend/utils/adt/json.c @@ -81,9 +81,10 @@ json_in(PG_FUNCTION_ARGS) /* validate it */ lex = makeJsonLexContext(result, false); - pg_parse_json_or_ereport(lex, &nullSemAction); + if (!pg_parse_json_or_errsave(lex, &nullSemAction, fcinfo->context)) + PG_RETURN_NULL(); - /* Internal representation is the same as text, for now */ + /* Internal representation is the same as text */ PG_RETURN_TEXT_P(result); } @@ -1337,7 +1338,7 @@ json_typeof(PG_FUNCTION_ARGS) /* Lex exactly one token from the input and check its type. */ result = json_lex(lex); if (result != JSON_SUCCESS) - json_ereport_error(result, lex); + json_errsave_error(result, lex, NULL); tok = lex->token_type; switch (tok) { -- cgit v1.2.3