Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pLThr-0003ZX-2g for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Jan 2023 18:44:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pLThq-0005vH-1D for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Jan 2023 18:44:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pLThp-0005v8-Nn for pgsql-hackers@lists.postgresql.org; Fri, 27 Jan 2023 18:44:09 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pLThm-00029a-Kp for pgsql-hackers@postgresql.org; Fri, 27 Jan 2023 18:44:09 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id B6B455C00BB; Fri, 27 Jan 2023 13:44:02 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 27 Jan 2023 13:44:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1674845042; x=1674931442; bh=E JBnkCP5ieMTuW/AbtjIiR49yDmWNfI/BrMOgnGZaXQ=; b=ISe3iwmQzFYNPx+fv boobLvfK0z2CG5ESPyNtvhCLEHhaGgWFKrRk/WPfaan53Vx8N+GwOCE6mWhAGvA2 XndtevOHL2nCudHWxdQMJ9HiZ8CKC+WzY43+EEoBcvsUR8rb8aAkGSPwiL4jib+f 7k5vH5dumEwR7givuxMql+GXrOYAc2Y5ycEIhYKQ0tyZY5pxrp407glieRJc5lQw pufHao5+RSTXhXueH0OPOn3yH85bIvbUJ/6AsGXoQPTVyQ8yx29qZyWlW+iEOqXA 1bYfjrQu/7o/Hu1wSo92i/aqHxRB2PTo2tQYGc6wkCAGb+H77Imghl9IG1UAUDS/ toaDg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedruddviedgudduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhv rghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorh hgqeenucggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfejjefhgfeiueeukeej keffgfdufffhudffffeuveenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtoh hmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghl vhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Jan 2023 13:44:02 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id DF5B898; Fri, 27 Jan 2023 19:31:19 +0100 (CET) Date: Fri, 27 Jan 2023 19:31:19 +0100 From: Alvaro Herrera To: Nathan Bossart Cc: Tom Lane , Robert Haas , "pgsql-hackers@postgresql.org" Subject: Re: improving user.c error messages Message-ID: <20230127183119.e5jtyh4g2md57ctb@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230127000936.GA1998073@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk While we're here, On 2023-Jan-26, Nathan Bossart wrote: > @@ -838,7 +867,8 @@ AlterRole(ParseState *pstate, AlterRoleStmt *stmt) > if (!should_be_super && roleid == BOOTSTRAP_SUPERUSERID) > ereport(ERROR, > (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), > - errmsg("permission denied: bootstrap user must be superuser"))); > + errmsg("permission denied to alter role"), > + errdetail("The bootstrap user must be superuser."))); I think this one isn't using the right errcode; this is not a case of insufficient privileges. There's no priv you can acquire that lets you do it. So I'd change it to unsupported operation. I was confused a bit by this one: > /* an unprivileged user can change their own password */ > if (dpassword && roleid != currentUserId) > ereport(ERROR, > (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), > - errmsg("must have CREATEROLE privilege to change another user's password"))); > + errmsg("permission denied to alter role"), > + errdetail("To change another role's password, you must have %s privilege and %s on the role.", > + "CREATEROLE", "ADMIN OPTION"))); > } In no other message we say what operation is being attempted in the errdetail; all the others start with "You must have" and that's it. However, looking closer I think this one being different is okay, because the errmsg() you're using is vague, and I think the error report would be confusing if you were to remove the "To change another role's password" bit. The patch looks good to me. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/