pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Replace run-time error check with assertion
2+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2021-05-27 388e75ad33  Replace run-time error check with assertion
* Replace run-time error check with assertion
@ 2021-05-25 09:28 Peter Eisentraut <peter.eisentraut@enterprisedb.com>
  2021-05-25 14:51 ` Re: Replace run-time error check with assertion Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Peter Eisentraut @ 2021-05-25 09:28 UTC (permalink / raw)
  To: pgsql-hackers


In the attached patch, the error message was checking that the 
structures returned from the parser matched expectations.  That's 
something we usually use assertions for, not a full user-facing error 
message.  So I replaced that with an assertion (hidden inside 
lfirst_node()).

Attachments:

0001-Replace-run-time-error-check-with-assertion.patch (text/plain, 1.7K) download From a30697758c475db2f4333cedbe6aad1e1acd0ee8 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut <peter@eisentraut.org> Date: Tue, 25 May 2021 11:27:04 +0200 Subject: [PATCH] Replace run-time error check with assertion The error message was checking that the structures returned from the parser matched expectations. That's something we usually use assertions for, not a full user-facing error message. --- src/backend/commands/statscmds.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.c index acae19176c..b244a0fbd7 100644 --- a/src/backend/commands/statscmds.c +++ b/src/backend/commands/statscmds.c @@ -220,26 +220,14 @@ CreateStatistics(CreateStatsStmt *stmt) */ foreach(cell, stmt->exprs) { - Node *expr = (Node *) lfirst(cell); - StatsElem *selem; - HeapTuple atttuple; - Form_pg_attribute attForm; - TypeCacheEntry *type; - - /* - * We should not get anything else than StatsElem, given the grammar. - * But let's keep it as a safety. - */ - if (!IsA(expr, StatsElem)) - ereport(ERROR, - (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("only simple column references and expressions are allowed in CREATE STATISTICS"))); - - selem = (StatsElem *) expr; + StatsElem *selem = lfirst_node(StatsElem, cell); if (selem->name) /* column reference */ { char *attname; + HeapTuple atttuple; + Form_pg_attribute attForm; + TypeCacheEntry *type; attname = selem->name; @@ -273,6 +261,7 @@ CreateStatistics(CreateStatsStmt *stmt) { Node *expr = selem->expr; Oid atttype; + TypeCacheEntry *type; Assert(expr != NULL); -- 2.31.1
^ permalink raw reply [nested|flat] 2+ messages in thread

* Re: Replace run-time error check with assertion
  2021-05-25 09:28 Replace run-time error check with assertion Peter Eisentraut <peter.eisentraut@enterprisedb.com>
@ 2021-05-25 14:51 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2021-05-25 14:51 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@enterprisedb.com>; +Cc: pgsql-hackers

Peter Eisentraut <peter.eisentraut@enterprisedb.com> writes:
> In the attached patch, the error message was checking that the 
> structures returned from the parser matched expectations.  That's 
> something we usually use assertions for, not a full user-facing error 
> message.  So I replaced that with an assertion (hidden inside 
> lfirst_node()).

Works for me.  It's certainly silly to use a translatable ereport
rather than elog for this.

Localizing those variables some more looks sane too.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2021-05-25 14:51 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-05-25 09:28 Replace run-time error check with assertion Peter Eisentraut <peter.eisentraut@enterprisedb.com>
2021-05-25 14:51 ` Tom Lane <tgl@sss.pgh.pa.us>

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