diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2022-12-11 11:28:15 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2022-12-11 11:28:15 -0500 |
commit | c60c9badba9b4db3155eef081ae0b923f983168c (patch) | |
tree | 60b12d49fa9f01feff7707cef18fac7ebf24ab18 /src/include/utils/jsonfuncs.h | |
parent | 50428a301d5ad46316cac2192f2ca8d91898aa3c (diff) | |
download | postgresql-c60c9badba9b4db3155eef081ae0b923f983168c.tar.gz postgresql-c60c9badba9b4db3155eef081ae0b923f983168c.zip |
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
Diffstat (limited to 'src/include/utils/jsonfuncs.h')
-rw-r--r-- | src/include/utils/jsonfuncs.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/include/utils/jsonfuncs.h b/src/include/utils/jsonfuncs.h index 865b2ff7c11..7fad0269f62 100644 --- a/src/include/utils/jsonfuncs.h +++ b/src/include/utils/jsonfuncs.h @@ -39,11 +39,16 @@ typedef text *(*JsonTransformStringValuesAction) (void *state, char *elem_value, /* build a JsonLexContext from a text datum */ extern JsonLexContext *makeJsonLexContext(text *json, bool need_escapes); -/* try to parse json, and ereport(ERROR) on failure */ -extern void pg_parse_json_or_ereport(JsonLexContext *lex, JsonSemAction *sem); +/* try to parse json, and errsave(escontext) on failure */ +extern bool pg_parse_json_or_errsave(JsonLexContext *lex, JsonSemAction *sem, + struct Node *escontext); -/* report an error during json lexing or parsing */ -extern void json_ereport_error(JsonParseErrorType error, JsonLexContext *lex); +#define pg_parse_json_or_ereport(lex, sem) \ + (void) pg_parse_json_or_errsave(lex, sem, NULL) + +/* save an error during json lexing or parsing */ +extern void json_errsave_error(JsonParseErrorType error, JsonLexContext *lex, + struct Node *escontext); extern uint32 parse_jsonb_index_flags(Jsonb *jb); extern void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state, |