Re: [PATCH] Make jsonapi usable from libpq
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Jacob Champion <pchampion@vmware.com>
Cc: "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2021-06-24T05:56:04Z
Lists: pgsql-hackers
Attachments
- jsonapi-libpq.patch (text/x-diff) patch
On Tue, Jun 22, 2021 at 10:59:37PM +0000, Jacob Champion wrote: > Hmm. I'm honestly hesitant to start splitting files apart, mostly > because json_log_and_abort() is only called from two places, and both > those places are triggered by programmer error as opposed to user > error. > > Would it make more sense to switch to an fprintf-and-abort case, to > match the approach taken by PGTHREAD_ERROR and the out-of-memory > conditions in fe-print.c? Or is there already precedent for handling > can't-happen code paths with in-band errors, through the PGconn? Not really.. Looking more closely at that, I actually find a bit crazy the requirement for any logging within jsonapi.c just to cope with the fact that json_errdetail() and report_parse_error() just want to track down if the caller is giving some garbage or not, which should never be the case, really. So I would be tempted to eliminate this dependency to begin with. The second thing is how we should try to handle the way the error message gets allocated in json_errdetail(). libpq cannot rely on psprintf(), so I can think about two options here: - Let the caller of json_errdetail() allocate the memory area of the error message by itself, pass it down to the function. - Do the allocation within json_errdetail(), and let callers cope the case where json_errdetail() itself fails on OOM for any frontend code using it. Looking at HEAD, the OAUTH patch and the token handling, the second option looks more interesting. I have to admit that handling the token part makes the patch a bit special, but that avoids duplicating all those error messages for libpq. Please see the idea as attached. -- Michael
Commits
-
Remove libpq's use of abort(3) to handle mutex failure cases.
- aaddf6ba09e2 15.0 landed
-
Don't use abort(3) in libpq's fe-print.c.
- cf1f545bf281 14.0 landed
- b54be47cdc2d 9.6.23 landed
- 34c24e5a4337 11.13 landed
- 240d56fc4351 12.8 landed
- 1603deca34ef 13.4 landed
- 06a2b2fe5580 10.18 landed
- 6f5d9bce57a7 15.0 landed
-
Remove undesirable libpq dependency on stringinfo.c.
- 8ec00dc5cd70 14.0 landed
-
Remove arbitrary line length limit for libpq service files.
- c0cb87fbb664 14.0 cited
-
Use abort() instead of exit() to abort library functions
- c6ea8ccea6bf 9.2.0 cited