Re: Better error reporting from extension scripts (Was: Extend ALTER OPERATOR)
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Christoph Berg <myon@debian.org>
Cc: Michael Banck <mbanck@gmx.net>, Tommy Pavlicek <tommypav122@gmail.com>, Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>, pgsql-hackers@lists.postgresql.org, jian.universality@gmail.com
Date: 2024-09-28T19:45:36Z
Lists: pgsql-hackers
Attachments
- v3-0001-Improve-parser-s-reporting-of-statement-start-loc.patch (text/x-diff) patch v3-0001
- v3-0002-Improve-reporting-of-errors-in-extension-script-f.patch (text/x-diff) patch v3-0002
I wrote: > It looks like if we did want to suppress that, the right fix is to > make gram.y track statement start locations more honestly, as in > 0002 attached (0001 is the same as before). I did a little bit of further work on this: * I ran some performance checks and convinced myself that indeed the more complex definition of YYLLOC_DEFAULT has no measurable cost compared to the overall runtime of raw_parser(), never mind later processing. So I see no reason not to go ahead with that change. I swapped the two patches to make that 0001, and added a regression test illustrating its effect on pg_stat_statements. (Without the gram.y change, the added slash-star comment shows up in the pg_stat_statements output, which is surely odd.) * I concluded that the best way to report the individual statement when we're able to do that is to include it in an errcontext() message, similar to what spi.c's _SPI_error_callback does. Otherwise it interacts badly if some more-tightly-nested error context function has already set up an "internal error query", as for example SQL function errors will do if you enable check_function_bodies = on. So here's v3, now with commit messages and regression tests. I feel like this is out of the proof-of-concept stage and might now actually be committable. There's still a question of whether reporting the whole script as the query is OK when we have a syntax error, but I have no good ideas as to how to make that terser. And I think you're right that we shouldn't let perfection stand in the way of making things noticeably better. regards, tom lane
Commits
-
Strip Windows newlines from extension script files manually.
- 6cfb3a337469 18.0 landed
-
Read extension script files in text not binary mode.
- 924e03917d6f 18.0 landed
-
Improve reporting of errors in extension script files.
- 774171c4f640 18.0 landed
-
Improve parser's reporting of statement start locations.
- 14e5680eee19 18.0 landed
-
Extend ALTER OPERATOR to allow setting more optimization attributes.
- 2b5154beab79 17.0 landed
-
Core support for "extensions", which are packages of SQL objects.
- d9572c4e3b47 9.1.0 cited