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: Improve reporting of errors in extension script files.
Date: Tue, 22 Oct 2024 15:36:31 +0000
Message-ID: <E1t3Gvw-001vQ4-83@gemulon.postgresql.org> (raw)

Improve reporting of errors in extension script files.

Previously, CREATE/ALTER EXTENSION gave basically no useful
context about errors reported while executing script files.
I think the idea was that you could run the same commands
manually to see the error, but that's often quite inconvenient.
Let's improve that.

If we get an error during raw parsing, we won't have a current
statement identified by a RawStmt node, but we should always get
a syntax error position.  Show the portion of the script from
the last semicolon-newline before the error position to the first
one after it.  There are cases where this might show only a
fragment of a statement, but that should be uncommon, and it
seems better than showing the whole script file.

Without an error cursor, if we have gotten past raw parsing (which
we probably have), we can report just the current SQL statement as
an item of error context.

In any case also report the script file name as error context,
since it might not be entirely obvious which of a series of
update scripts failed.  We can also show an approximate script
line number in case whatever we printed of the query isn't
sufficiently identifiable.

The error-context code path is already exercised by some
test_extensions test cases, but add tests for the syntax-error
path.

Discussion: https://postgr.es/m/ZvV1ClhnbJLCz7Sm@msg.df7cb.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/774171c4f640853b1cf8747a4762631d2f5d25be

Modified Files
--------------
src/backend/commands/extension.c                   | 167 ++++++++++++++++++++-
src/test/modules/test_extensions/Makefile          |   4 +-
.../test_extensions/expected/test_extensions.out   |  42 ++++++
src/test/modules/test_extensions/meson.build       |   2 +
.../test_extensions/sql/test_extensions.sql        |   4 +
.../test_extensions/test_ext7--2.0--2.1bad.sql     |  14 ++
.../test_extensions/test_ext7--2.0--2.2bad.sql     |  13 ++
src/tools/pgindent/typedefs.list                   |   1 +
8 files changed, 244 insertions(+), 3 deletions(-)



Message-ID: <E1t3Gvw-001vQ4-83@gemulon.postgresql.org>
Permalink:  ../E1t3Gvw-001vQ4-83@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1t3Gvw-001vQ4-83@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Improve reporting of errors in extension script files.
  In-Reply-To: <E1t3Gvw-001vQ4-83@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