pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: Amit Kapila <amit.kapila16@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: Julien Rouhaud <rjuju123@gmail.com>
Cc: Masahiko Sawada <masahiko.sawada@2ndquadrant.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Missing errcode() in ereport
Date: Thu, 19 Mar 2020 19:32:55 -0400
Message-ID: <5995.1584660775@sss.pgh.pa.us> (raw)
In-Reply-To: <20200319230446.lxjybufdcgwaqkhj@alap3.anarazel.de>
References: <CA+fd4k6N8EjNvZpM8nme+y+05mz-SM8Z_BgkixzkA34R+ej0Kw@mail.gmail.com>
	<CAA4eK1KKmr-Dt-8=C=uoeKk7b6WqOTjjpMt_MXs4eFN1=kAX5w@mail.gmail.com>
	<CAOBaU_bb7FR5cF9RKN42kPHf6pk9CeQ=wTuieJv-t3MroU_q0g@mail.gmail.com>
	<20200317095839.GG2206@paquier.xyz>
	<CAA4eK1+powcFw2EAoVgvH4P3fspAJhxU-VTy0_cR2XpcBZGMAA@mail.gmail.com>
	<32174.1584454158@sss.pgh.pa.us>
	<20200319175902.vjib2tslosw65iyr@alap3.anarazel.de>
	<5063.1584641224@sss.pgh.pa.us>
	<20200319230446.lxjybufdcgwaqkhj@alap3.anarazel.de>

Andres Freund <andres@anarazel.de> writes:
> On 2020-03-19 14:07:04 -0400, Tom Lane wrote:
>> Now that we can rely on having varargs macros, I think we could
>> stop requiring the extra level of parentheses,

> I think that'd be an improvement, because:
> ane of the ones I saw confuse people is just:
> /home/andres/src/postgresql/src/backend/tcop/postgres.c:3727:4: error: ‘ereport’ undeclared (first use in this function); did you mean ‘rresvport’?
>  3727 |    ereport(FATAL,
>       |    ^~~~~~~
>       |    rresvport
> /home/andres/src/postgresql/src/backend/tcop/postgres.c:3727:4: note: each undeclared identifier is reported only once for each function it appears in
> because the extra parens haven't been added.

Ah, so the macro isn't expanded at all if it appears to have more than
two parameters?  That seems odd, but I suppose some compilers might
work that way.  Switching to varargs would improve that for sure.

> Another one I've both seen and committed byself is converting an elog to
> an ereport, and not adding an errcode() around the error code - which
> silently looks like it works.

You mean not adding errmsg() around the error string?  Yeah, I can
believe that one easily.  It's sort of the same problem as forgetting
to wrap errcode() around the ERRCODE_ constant.

I think that at least some compilers will complain about side-effect-free
subexpressions of a comma expression.  Could we restructure things so
that the errcode/errmsg/etc calls form a standalone comma expression
rather than appearing to be arguments of a varargs function?  The
compiler's got no hope of realizing there's anything wrong when it
thinks it's passing an integer or string constant to a function it knows
nothing about.  But if it could see that nothing at all is being done with
the constant, maybe we'd get somewhere.

			regards, tom lane





view thread (31+ messages)  latest in thread

Message-ID: <5995.1584660775@sss.pgh.pa.us>
Permalink:  ../5995.1584660775@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5995.1584660775@sss.pgh.pa.us

 · 

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-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, andres@anarazel.de, amit.kapila16@gmail.com, michael@paquier.xyz, rjuju123@gmail.com, masahiko.sawada@2ndquadrant.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: Missing errcode() in ereport
  In-Reply-To: <5995.1584660775@sss.pgh.pa.us>

* 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