summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pg_locale.c
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/adt/pg_locale.c
parent6897f0ec024582a570868939d3f34a6853374723 (diff)
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/adt/pg_locale.c')
-rw-r--r--src/backend/utils/adt/pg_locale.c21
1 files changed, 14 insertions, 7 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")));