Subject: Re: improving user.c error messages

From: Peter Eisentraut <[email-masked]>
Date: Fri, 27 Jan 2023 11:00:01 +0100

On 26.01.23 01:22, Nathan Bossart wrote:
> Here is an early draft of some modest improvements to the user.c error
> messages.  I basically just tried to standardize the style of and add
> context to the existing error messages.  I used errhint() for this extra
> context, but errdetail() would work, too.  This isn't perfect.  You might
> still have to go through a couple rounds of errors before your role has all
> the privileges it needs for a command, but this seems to improve matters a
> little.
> 
> I think there is still a lot of room for improvement, but I wanted to at
> least get the discussion started before I went too far.

This is good.  If I may assign some more work ;-), we have a bunch of 
error messages like

errmsg("must be superuser or a role with privileges of the 
pg_write_server_files role to create backup stored on server")

errmsg("must be superuser or have privileges of the 
pg_execute_server_program role to COPY to or from an external program")

errmsg("must be superuser or have privileges of pg_read_all_settings to 
examine \"%s\"", ...)

which could also be split up into a pair of

errmsg("permission denied to xxx")
errdetail("You must be superuser or ...")

---

From: Robert Haas <[email-masked]>
Date: Fri, 27 Jan 2023 08:31:32 -0500

> errdetail("You must be superuser or ...")

I almost hate to bring this up since I'm not sure how far we want to
go down this rat hole, but what should be our policy about mentioning
superuser? I don't think we're entirely consistent right now, and I'm
not sure whether every error message needs to mention that if you were
the superuser you could do everything. Is that something we should
mention always, never, or in some set of circumstances?

-- 
Robert Haas
EDB: http://www.enterprisedb.com

---

From: Nathan Bossart <[email-masked]>
Date: Fri, 27 Jan 2023 07:52:36 -0800

> mention always, never, or in some set of circumstances?

IMHO superuser should typically only be mentioned when it is the only way
to do something.  Since superusers have all privileges, I think logs like
"superuser or privileges of X" are kind of redundant.  If Robert has
privileges of X, we wouldn't say "privileges of X or Robert."  We'd just
point to X.  Ultimately, I feel like mentioning superuser in error messages
usually just makes the message longer without adding any useful
information.

I recognize that this is a bold opinion and that the policy to mention
superuser might need to be more nuanced in practice...

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

---

From: Robert Haas <[email-masked]>
Date: Fri, 27 Jan 2023 10:53:54 -0500

> usually just makes the message longer without adding any useful

That's kind of my opinion too, but I'm not sure whether there are
cases where it will lead to confusion.

---

From: Tom Lane <[email-masked]>
Date: Fri, 27 Jan 2023 11:17:13 -0500

> mention always, never, or in some set of circumstances?

Good point.  My vote is for standardizing on *not* mentioning it.
Error messages should say "you need privilege X".  That is not
the place to go into all the ways you could hold privilege X
(one of which is being superuser).

			regards, tom lane