pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Change JsonSemAction to allow non-throw error reporting.
Date: Sun, 11 Dec 2022 16:28:24 +0000
Message-ID: <E1p4PBf-003328-DG@gemulon.postgresql.org> (raw)

Change JsonSemAction to allow non-throw error reporting.

Formerly, semantic action functions for the JSON parser returned void,
so that there was no way for them to affect the parser's behavior.
That means in particular that they can't force an error exit except by
longjmp'ing.  That won't do in the context of our project to make input
functions return errors softly.  Hence, change them to return the same
JsonParseErrorType enum value as the parser itself uses.  If an action
function returns anything besides JSON_SUCCESS, the parse is abandoned
and that error code is returned.

Action functions can thus easily return the same error conditions that
the parser already knows about.  As an escape hatch for expansion, also
invent a code JSON_SEM_ACTION_FAILED that the core parser does not know
the exact meaning of.  When returning this code, an action function
must use some out-of-band mechanism for reporting the error details.

This commit simply makes the API change and causes all the existing
action functions to return JSON_SUCCESS, so that there is no actual
change in behavior here.  This is long enough and boring enough that
it seemed best to commit it separately from the changes that make
real use of the new mechanism.

In passing, remove a duplicate assignment of
transform_string_values_scalar.

Discussion: https://postgr.es/m/1436686.1670701118@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/50428a301d5ad46316cac2192f2ca8d91898aa3c

Modified Files
--------------
src/backend/utils/adt/jsonb.c            |  36 ++--
src/backend/utils/adt/jsonfuncs.c        | 356 ++++++++++++++++++++-----------
src/bin/pg_verifybackup/parse_manifest.c |  40 ++--
src/common/jsonapi.c                     |  57 ++++-
src/include/common/jsonapi.h             |  21 +-
5 files changed, 342 insertions(+), 168 deletions(-)



Message-ID: <E1p4PBf-003328-DG@gemulon.postgresql.org>
Permalink:  ../E1p4PBf-003328-DG@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1p4PBf-003328-DG@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Change JsonSemAction to allow non-throw error reporting.
  In-Reply-To: <E1p4PBf-003328-DG@gemulon.postgresql.org>
  References: <E1p4PBf-003328-DG@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox