mirror of
https://github.com/postgres/postgres.git
synced 2025-10-27 00:12:01 +03:00
Assign error codes where missing for user-facing failures
All the errors triggered in the code paths patched here would cause the backend to issue an internal_error errcode, which is a state that should be used only for "can't happen" situations. However, these code paths are reachable by the regression tests, and could be seen by users in valid cases. Some regression tests expect internal errcodes as they manipulate the backend state to cause corruption (like checksums), or use elog() because it is more convenient (like injection points), these have no need to change. This reduces the number of internal failures triggered in a check-world by more than half, while providing correct errcodes for these valid cases. Reviewed-by: Robert Haas Discussion: https://postgr.es/m/Zic_GNgos5sMxKoa@paquier.xyz
This commit is contained in:
@@ -803,7 +803,9 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner,
|
||||
* That's a pretty silly thing to do.)
|
||||
*/
|
||||
if (!foundUniqueIndex)
|
||||
elog(ERROR, "could not find suitable unique index on materialized view");
|
||||
ereport(ERROR,
|
||||
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("could not find suitable unique index on materialized view"));
|
||||
|
||||
appendStringInfoString(&querybuf,
|
||||
" AND newdata.* OPERATOR(pg_catalog.*=) mv.*) "
|
||||
|
||||
@@ -11363,7 +11363,8 @@ ATExecAlterConstraint(Relation rel, AlterTableCmd *cmd, bool recurse,
|
||||
}
|
||||
|
||||
ereport(ERROR,
|
||||
(errmsg("cannot alter constraint \"%s\" on relation \"%s\"",
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("cannot alter constraint \"%s\" on relation \"%s\"",
|
||||
cmdcon->conname, RelationGetRelationName(rel)),
|
||||
ancestorname && ancestortable ?
|
||||
errdetail("Constraint \"%s\" is derived from constraint \"%s\" of relation \"%s\".",
|
||||
|
||||
@@ -1519,6 +1519,7 @@ renametrig(RenameStmt *stmt)
|
||||
*/
|
||||
if (OidIsValid(trigform->tgparentid))
|
||||
ereport(ERROR,
|
||||
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("cannot rename trigger \"%s\" on table \"%s\"",
|
||||
stmt->subname, RelationGetRelationName(targetrel)),
|
||||
errhint("Rename the trigger on the partitioned table \"%s\" instead.",
|
||||
|
||||
@@ -1730,6 +1730,7 @@ AddRoleMems(Oid currentUserId, const char *rolename, Oid roleid,
|
||||
*/
|
||||
if (memberid == ROLE_PG_DATABASE_OWNER)
|
||||
ereport(ERROR,
|
||||
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("role \"%s\" cannot be a member of any role",
|
||||
get_rolespec_name(memberRole)));
|
||||
|
||||
@@ -2121,6 +2122,7 @@ check_role_membership_authorization(Oid currentUserId, Oid roleid,
|
||||
*/
|
||||
if (is_grant && roleid == ROLE_PG_DATABASE_OWNER)
|
||||
ereport(ERROR,
|
||||
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("role \"%s\" cannot have explicit members",
|
||||
GetUserNameFromId(roleid, false)));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user