Skip to content

Commit 0426f34

Browse files
committed
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
1 parent c80b5f6 commit 0426f34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+237
-610
lines changed

contrib/dblink/expected/dblink.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
CREATE EXTENSION dblink;
2+
-- want context for notices
3+
\set SHOW_CONTEXT always
24
CREATE TABLE foo(f1 int, f2 text, f3 text[], primary key (f1,f2));
35
INSERT INTO foo VALUES (0,'a','{"a0","b0","c0"}');
46
INSERT INTO foo VALUES (1,'b','{"a1","b1","c1"}');

contrib/dblink/sql/dblink.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
CREATE EXTENSION dblink;
22

3+
-- want context for notices
4+
\set SHOW_CONTEXT always
5+
36
CREATE TABLE foo(f1 int, f2 text, f3 text[], primary key (f1,f2));
47
INSERT INTO foo VALUES (0,'a','{"a0","b0","c0"}');
58
INSERT INTO foo VALUES (1,'b','{"a1","b1","c1"}');

contrib/hstore_plperl/expected/hstore_plperlu.out

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ INFO: $VAR1 = {
2929
'cc' => undef
3030
};
3131

32-
CONTEXT: PL/Perl function "test1"
3332
test1
3433
-------
3534
2
@@ -46,7 +45,6 @@ $$;
4645
SELECT test1none('aa=>bb, cc=>NULL'::hstore);
4746
INFO: $VAR1 = '"aa"=>"bb", "cc"=>NULL';
4847

49-
CONTEXT: PL/Perl function "test1none"
5048
test1none
5149
-----------
5250
0
@@ -67,7 +65,6 @@ INFO: $VAR1 = {
6765
'cc' => undef
6866
};
6967

70-
CONTEXT: PL/Perl function "test1list"
7168
test1list
7269
-----------
7370
2
@@ -92,7 +89,6 @@ $VAR2 = {
9289
'dd' => 'ee'
9390
};
9491

95-
CONTEXT: PL/Perl function "test1arr"
9692
test1arr
9793
----------
9894
2
@@ -120,10 +116,8 @@ INFO: $VAR1 = {
120116
'cc' => undef
121117
};
122118

123-
CONTEXT: PL/Perl function "test3"
124119
INFO: $VAR1 = '"a"=>"1", "b"=>"boo", "c"=>NULL';
125120

126-
CONTEXT: PL/Perl function "test3"
127121
test3
128122
-------
129123

@@ -161,7 +155,6 @@ INFO: $VAR1 = {
161155
}
162156
};
163157

164-
CONTEXT: PL/Perl function "test4"
165158
SELECT * FROM test1;
166159
a | b
167160
---+---------------------------------

contrib/hstore_plpython/expected/hstore_plpython.out

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ return len(val)
1313
$$;
1414
SELECT test1('aa=>bb, cc=>NULL'::hstore);
1515
INFO: [('aa', 'bb'), ('cc', None)]
16-
CONTEXT: PL/Python function "test1"
1716
test1
1817
-------
1918
2
@@ -32,7 +31,6 @@ return len(val)
3231
$$;
3332
SELECT test1n('aa=>bb, cc=>NULL'::hstore);
3433
INFO: [('aa', 'bb'), ('cc', None)]
35-
CONTEXT: PL/Python function "test1n"
3634
test1n
3735
--------
3836
2

contrib/ltree_plpython/expected/ltree_plpython.out

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ return len(val)
99
$$;
1010
SELECT test1('aa.bb.cc'::ltree);
1111
INFO: ['aa', 'bb', 'cc']
12-
CONTEXT: PL/Python function "test1"
1312
test1
1413
-------
1514
3
@@ -24,7 +23,6 @@ return len(val)
2423
$$;
2524
SELECT test1n('aa.bb.cc'::ltree);
2625
INFO: ['aa', 'bb', 'cc']
27-
CONTEXT: PL/Python function "test1n"
2826
test1n
2927
--------
3028
3

contrib/sepgsql/expected/alter.out

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,10 @@ LINE 1: ..."regtest_schema"."regtest_table_3" pk ON ( pk."x" OPERATOR(p...
166166
^
167167
QUERY: SELECT fk."a" FROM ONLY "regtest_schema_2"."regtest_table" fk LEFT OUTER JOIN ONLY "regtest_schema"."regtest_table_3" pk ON ( pk."x" OPERATOR(pg_catalog.=) fk."a") WHERE pk."x" IS NULL AND (fk."a" IS NOT NULL)
168168
LOG: SELinux: allowed { search } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=system_u:object_r:sepgsql_schema_t:s0 tclass=db_schema name="pg_catalog"
169-
CONTEXT: SQL statement "SELECT fk."a" FROM ONLY "regtest_schema_2"."regtest_table" fk LEFT OUTER JOIN ONLY "regtest_schema"."regtest_table_3" pk ON ( pk."x" OPERATOR(pg_catalog.=) fk."a") WHERE pk."x" IS NULL AND (fk."a" IS NOT NULL)"
170169
LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_table name="regtest_schema_2.regtest_table"
171-
CONTEXT: SQL statement "SELECT fk."a" FROM ONLY "regtest_schema_2"."regtest_table" fk LEFT OUTER JOIN ONLY "regtest_schema"."regtest_table_3" pk ON ( pk."x" OPERATOR(pg_catalog.=) fk."a") WHERE pk."x" IS NULL AND (fk."a" IS NOT NULL)"
172170
LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="table regtest_table column a"
173-
CONTEXT: SQL statement "SELECT fk."a" FROM ONLY "regtest_schema_2"."regtest_table" fk LEFT OUTER JOIN ONLY "regtest_schema"."regtest_table_3" pk ON ( pk."x" OPERATOR(pg_catalog.=) fk."a") WHERE pk."x" IS NULL AND (fk."a" IS NOT NULL)"
174171
LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_table name="regtest_schema.regtest_table_3"
175-
CONTEXT: SQL statement "SELECT fk."a" FROM ONLY "regtest_schema_2"."regtest_table" fk LEFT OUTER JOIN ONLY "regtest_schema"."regtest_table_3" pk ON ( pk."x" OPERATOR(pg_catalog.=) fk."a") WHERE pk."x" IS NULL AND (fk."a" IS NOT NULL)"
176172
LOG: SELinux: allowed { select } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="table regtest_table_3 column x"
177-
CONTEXT: SQL statement "SELECT fk."a" FROM ONLY "regtest_schema_2"."regtest_table" fk LEFT OUTER JOIN ONLY "regtest_schema"."regtest_table_3" pk ON ( pk."x" OPERATOR(pg_catalog.=) fk."a") WHERE pk."x" IS NULL AND (fk."a" IS NOT NULL)"
178173
ALTER TABLE regtest_table ADD CONSTRAINT test_ck CHECK (b like '%abc%') NOT VALID; -- not supported
179174
ALTER TABLE regtest_table VALIDATE CONSTRAINT test_ck; -- not supported
180175
ALTER TABLE regtest_table DROP CONSTRAINT test_ck; -- not supported

contrib/sepgsql/expected/label.out

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ SET client_min_messages = log;
136136
SELECT f1(); -- normal procedure
137137
LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=unconfined_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="public.f1()"
138138
LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.sepgsql_getcon()"
139-
CONTEXT: SQL function "f1" statement 1
140139
f1
141140
-----------------------------------------------------
142141
unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0
@@ -147,7 +146,6 @@ LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_re
147146
LOG: SELinux: allowed { entrypoint } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=system_u:object_r:sepgsql_trusted_proc_exec_t:s0 tclass=db_procedure name="function f2()"
148147
LOG: SELinux: allowed { transition } scontext=unconfined_u:unconfined_r:sepgsql_regtest_user_t:s0 tcontext=unconfined_u:unconfined_r:sepgsql_trusted_proc_t:s0 tclass=process
149148
LOG: SELinux: allowed { execute } scontext=unconfined_u:unconfined_r:sepgsql_trusted_proc_t:s0 tcontext=system_u:object_r:sepgsql_proc_exec_t:s0 tclass=db_procedure name="pg_catalog.sepgsql_getcon()"
150-
CONTEXT: SQL function "f2" statement 1
151149
f2
152150
-----------------------------------------------------
153151
unconfined_u:unconfined_r:sepgsql_trusted_proc_t:s0

doc/src/sgml/libpq.sgml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5582,6 +5582,46 @@ PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);
55825582
</listitem>
55835583
</varlistentry>
55845584

5585+
<varlistentry id="libpq-pqseterrorcontextvisibility">
5586+
<term>
5587+
<function>PQsetErrorContextVisibility</function>
5588+
<indexterm>
5589+
<primary>PQsetErrorContextVisibility</primary>
5590+
</indexterm>
5591+
</term>
5592+
5593+
<listitem>
5594+
<para>
5595+
Determines the handling of <literal>CONTEXT</> fields in messages
5596+
returned by <function>PQerrorMessage</>
5597+
and <function>PQresultErrorMessage</>.
5598+
<synopsis>
5599+
typedef enum
5600+
{
5601+
PQSHOW_CONTEXT_NEVER,
5602+
PQSHOW_CONTEXT_ERRORS,
5603+
PQSHOW_CONTEXT_ALWAYS
5604+
} PGContextVisibility;
5605+
5606+
PGContextVisibility PQsetErrorContextVisibility(PGconn *conn, PGContextVisibility show_context);
5607+
</synopsis>
5608+
5609+
<function>PQsetErrorContextVisibility</> sets the context display mode,
5610+
returning the connection's previous setting. This mode controls
5611+
whether the <literal>CONTEXT</literal> field is included in messages
5612+
(unless the verbosity setting is <firstterm>TERSE</>, in which
5613+
case <literal>CONTEXT</> is never shown). The <firstterm>NEVER</> mode
5614+
never includes <literal>CONTEXT</>, while <firstterm>ALWAYS</> always
5615+
includes it if available. In <firstterm>ERRORS</> mode (the
5616+
default), <literal>CONTEXT</> fields are included only for error
5617+
messages, not for notices and warnings. Changing this mode does not
5618+
affect the messages available from
5619+
already-existing <structname>PGresult</> objects, only
5620+
subsequently-created ones.
5621+
</para>
5622+
</listitem>
5623+
</varlistentry>
5624+
55855625
<varlistentry id="libpq-pqtrace">
55865626
<term>
55875627
<function>PQtrace</function>

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,6 +3190,21 @@ bar
31903190
</listitem>
31913191
</varlistentry>
31923192

3193+
<varlistentry>
3194+
<term><varname>SHOW_CONTEXT</varname></term>
3195+
<listitem>
3196+
<para>
3197+
This variable can be set to the
3198+
values <literal>never</>, <literal>errors</>, or <literal>always</>
3199+
to control whether <literal>CONTEXT</> fields are displayed in
3200+
messages from the server. The default is <literal>errors</> (meaning
3201+
that context will be shown in error messages, but not in notice or
3202+
warning messages). This setting has no effect
3203+
when <varname>VERBOSITY</> is set to <literal>terse</>.
3204+
</para>
3205+
</listitem>
3206+
</varlistentry>
3207+
31933208
<varlistentry>
31943209
<term><varname>SINGLELINE</varname></term>
31953210
<listitem>

src/bin/psql/command.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,7 @@ SyncVariables(void)
20292029

20302030
/* send stuff to it, too */
20312031
PQsetErrorVerbosity(pset.db, pset.verbosity);
2032+
PQsetErrorContextVisibility(pset.db, pset.show_context);
20322033
}
20332034

20342035
/*

0 commit comments

Comments
 (0)