mirror of
https://github.com/postgres/postgres.git
synced 2025-06-25 01:02:05 +03:00
Rearrange the handling of error context reports.
Remove the code in plpgsql that suppressed the innermost line of CONTEXT for messages emitted by RAISE commands. That was never more than a quick backwards-compatibility hack, and it's pretty silly in cases where the RAISE is nested in several levels of function. What's more, it violated our design theory that verbosity of error reports should be controlled on the client side not the server side. To alleviate the resulting noise increase, introduce a feature in libpq and psql whereby the CONTEXT field of messages can be suppressed, either always or only for non-error messages. Printing CONTEXT for errors only is now their default behavior. The actual code changes here are pretty small, but the effects on the regression test outputs are widespread. I had to edit some of the alternative expected outputs by hand; hopefully the buildfarm will soon find anything I fat-fingered. In passing, fix up (again) the output line counts in psql's various help displays. Add some commentary about how to verify them. Pavel Stehule, reviewed by Petr Jelínek, Jeevan Chalke, and others
This commit is contained in:
@ -169,3 +169,4 @@ PQsslInUse 166
|
||||
PQsslStruct 167
|
||||
PQsslAttributes 168
|
||||
PQsslAttribute 169
|
||||
PQsetErrorContextVisibility 170
|
||||
|
@ -2782,6 +2782,7 @@ makeEmptyPGconn(void)
|
||||
conn->client_encoding = PG_SQL_ASCII;
|
||||
conn->std_strings = false; /* unless server says differently */
|
||||
conn->verbosity = PQERRORS_DEFAULT;
|
||||
conn->show_context = PQSHOW_CONTEXT_ERRORS;
|
||||
conn->sock = PGINVALID_SOCKET;
|
||||
conn->auth_req_received = false;
|
||||
conn->password_needed = false;
|
||||
@ -5553,6 +5554,18 @@ PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity)
|
||||
return old;
|
||||
}
|
||||
|
||||
PGContextVisibility
|
||||
PQsetErrorContextVisibility(PGconn *conn, PGContextVisibility show_context)
|
||||
{
|
||||
PGContextVisibility old;
|
||||
|
||||
if (!conn)
|
||||
return PQSHOW_CONTEXT_ERRORS;
|
||||
old = conn->show_context;
|
||||
conn->show_context = show_context;
|
||||
return old;
|
||||
}
|
||||
|
||||
void
|
||||
PQtrace(PGconn *conn, FILE *debug_port)
|
||||
{
|
||||
|
@ -250,7 +250,7 @@ pqParseInput3(PGconn *conn)
|
||||
if (!conn->result)
|
||||
{
|
||||
printfPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("out of memory"));
|
||||
libpq_gettext("out of memory"));
|
||||
pqSaveErrorResult(conn);
|
||||
}
|
||||
}
|
||||
@ -321,7 +321,7 @@ pqParseInput3(PGconn *conn)
|
||||
if (!conn->result)
|
||||
{
|
||||
printfPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("out of memory"));
|
||||
libpq_gettext("out of memory"));
|
||||
pqSaveErrorResult(conn);
|
||||
}
|
||||
}
|
||||
@ -934,9 +934,14 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
|
||||
val = PQresultErrorField(res, PG_DIAG_INTERNAL_QUERY);
|
||||
if (val)
|
||||
appendPQExpBuffer(&workBuf, libpq_gettext("QUERY: %s\n"), val);
|
||||
val = PQresultErrorField(res, PG_DIAG_CONTEXT);
|
||||
if (val)
|
||||
appendPQExpBuffer(&workBuf, libpq_gettext("CONTEXT: %s\n"), val);
|
||||
if (conn->show_context == PQSHOW_CONTEXT_ALWAYS ||
|
||||
(conn->show_context == PQSHOW_CONTEXT_ERRORS && isError))
|
||||
{
|
||||
val = PQresultErrorField(res, PG_DIAG_CONTEXT);
|
||||
if (val)
|
||||
appendPQExpBuffer(&workBuf, libpq_gettext("CONTEXT: %s\n"),
|
||||
val);
|
||||
}
|
||||
}
|
||||
if (conn->verbosity == PQERRORS_VERBOSE)
|
||||
{
|
||||
|
@ -110,6 +110,13 @@ typedef enum
|
||||
PQERRORS_VERBOSE /* all the facts, ma'am */
|
||||
} PGVerbosity;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PQSHOW_CONTEXT_NEVER, /* never show CONTEXT field */
|
||||
PQSHOW_CONTEXT_ERRORS, /* show CONTEXT for errors only (default) */
|
||||
PQSHOW_CONTEXT_ALWAYS /* always show CONTEXT field */
|
||||
} PGContextVisibility;
|
||||
|
||||
/*
|
||||
* PGPing - The ordering of this enum should not be altered because the
|
||||
* values are exposed externally via pg_isready.
|
||||
@ -337,6 +344,10 @@ extern void PQinitOpenSSL(int do_ssl, int do_crypto);
|
||||
/* Set verbosity for PQerrorMessage and PQresultErrorMessage */
|
||||
extern PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);
|
||||
|
||||
/* Set CONTEXT visibility for PQerrorMessage and PQresultErrorMessage */
|
||||
extern PGContextVisibility PQsetErrorContextVisibility(PGconn *conn,
|
||||
PGContextVisibility show_context);
|
||||
|
||||
/* Enable/disable tracing */
|
||||
extern void PQtrace(PGconn *conn, FILE *debug_port);
|
||||
extern void PQuntrace(PGconn *conn);
|
||||
|
@ -394,6 +394,7 @@ struct pg_conn
|
||||
int client_encoding; /* encoding id */
|
||||
bool std_strings; /* standard_conforming_strings */
|
||||
PGVerbosity verbosity; /* error/notice message verbosity */
|
||||
PGContextVisibility show_context; /* whether to show CONTEXT field */
|
||||
PGlobjfuncs *lobjfuncs; /* private state for large-object access fns */
|
||||
|
||||
/* Buffer for data received from backend and not yet processed */
|
||||
|
Reference in New Issue
Block a user