aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2024-07-04 09:48:40 +0900
committerMichael Paquier <michael@paquier.xyz>2024-07-04 09:48:40 +0900
commitb81a71aa05f294705e1b1d4fe24548f175f9bfe9 (patch)
tree8d1c94fdfd570891b7b2e5b7f079eaf252e018b8 /src/backend/utils
parent6897f0ec024582a570868939d3f34a6853374723 (diff)
downloadpostgresql-b81a71aa05f294705e1b1d4fe24548f175f9bfe9.tar.gz
postgresql-b81a71aa05f294705e1b1d4fe24548f175f9bfe9.zip
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
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/pg_locale.c21
-rw-r--r--src/backend/utils/adt/tid.c24
2 files changed, 31 insertions, 14 deletions
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index 7e5bb2b703a..2673bafe60a 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -1481,7 +1481,8 @@ make_icu_collator(const char *iculocstr,
UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL, &status);
if (U_FAILURE(status))
ereport(ERROR,
- (errmsg("could not open collator for locale \"%s\" with rules \"%s\": %s",
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("could not open collator for locale \"%s\" with rules \"%s\": %s",
iculocstr, icurules, u_errorName(status))));
}
@@ -2609,7 +2610,8 @@ pg_ucol_open(const char *loc_str)
if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING)
{
ereport(ERROR,
- (errmsg("could not get language from locale \"%s\": %s",
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("could not get language from locale \"%s\": %s",
loc_str, u_errorName(status))));
}
@@ -2630,7 +2632,8 @@ pg_ucol_open(const char *loc_str)
if (U_FAILURE(status))
ereport(ERROR,
/* use original string for error report */
- (errmsg("could not open collator for locale \"%s\": %s",
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("could not open collator for locale \"%s\": %s",
orig_str, u_errorName(status))));
if (U_ICU_VERSION_MAJOR_NUM < 54)
@@ -2646,7 +2649,8 @@ pg_ucol_open(const char *loc_str)
{
ucol_close(collator);
ereport(ERROR,
- (errmsg("could not open collator for locale \"%s\": %s",
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("could not open collator for locale \"%s\": %s",
orig_str, u_errorName(status))));
}
}
@@ -2957,7 +2961,8 @@ icu_language_tag(const char *loc_str, int elevel)
if (elevel > 0)
ereport(elevel,
- (errmsg("could not convert locale name \"%s\" to language tag: %s",
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("could not convert locale name \"%s\" to language tag: %s",
loc_str, u_errorName(status))));
return NULL;
}
@@ -2998,7 +3003,8 @@ icu_validate_locale(const char *loc_str)
if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING)
{
ereport(elevel,
- (errmsg("could not get language from ICU locale \"%s\": %s",
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("could not get language from ICU locale \"%s\": %s",
loc_str, u_errorName(status)),
errhint("To disable ICU locale validation, set the parameter \"%s\" to \"%s\".",
"icu_validation_level", "disabled")));
@@ -3027,7 +3033,8 @@ icu_validate_locale(const char *loc_str)
if (!found)
ereport(elevel,
- (errmsg("ICU locale \"%s\" has unknown language \"%s\"",
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("ICU locale \"%s\" has unknown language \"%s\"",
loc_str, lang),
errhint("To disable ICU locale validation, set the parameter \"%s\" to \"%s\".",
"icu_validation_level", "disabled")));
diff --git a/src/backend/utils/adt/tid.c b/src/backend/utils/adt/tid.c
index 8cff1e7a12e..dd46001a4eb 100644
--- a/src/backend/utils/adt/tid.c
+++ b/src/backend/utils/adt/tid.c
@@ -312,9 +312,11 @@ currtid_internal(Relation rel, ItemPointer tid)
return currtid_for_view(rel, tid);
if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
- elog(ERROR, "cannot look at latest visible tid for relation \"%s.%s\"",
- get_namespace_name(RelationGetNamespace(rel)),
- RelationGetRelationName(rel));
+ ereport(ERROR,
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot look at latest visible tid for relation \"%s.%s\"",
+ get_namespace_name(RelationGetNamespace(rel)),
+ RelationGetRelationName(rel)));
ItemPointerCopy(tid, result);
@@ -349,16 +351,22 @@ currtid_for_view(Relation viewrel, ItemPointer tid)
if (strcmp(NameStr(attr->attname), "ctid") == 0)
{
if (attr->atttypid != TIDOID)
- elog(ERROR, "ctid isn't of type TID");
+ ereport(ERROR,
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("ctid isn't of type TID"));
tididx = i;
break;
}
}
if (tididx < 0)
- elog(ERROR, "currtid cannot handle views with no CTID");
+ ereport(ERROR,
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("currtid cannot handle views with no CTID"));
rulelock = viewrel->rd_rules;
if (!rulelock)
- elog(ERROR, "the view has no rules");
+ ereport(ERROR,
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("the view has no rules"));
for (i = 0; i < rulelock->numLocks; i++)
{
rewrite = rulelock->rules[i];
@@ -368,7 +376,9 @@ currtid_for_view(Relation viewrel, ItemPointer tid)
TargetEntry *tle;
if (list_length(rewrite->actions) != 1)
- elog(ERROR, "only one select rule is allowed in views");
+ ereport(ERROR,
+ errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("only one select rule is allowed in views"));
query = (Query *) linitial(rewrite->actions);
tle = get_tle_by_resno(query->targetList, tididx + 1);
if (tle && tle->expr && IsA(tle->expr, Var))