summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-09-20 13:23:40 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-09-20 13:23:55 -0400
commit226bc87c2da98ebd9ac08d1677961cb5e7ea4e5a (patch)
tree5a8190fc067edab8eb1298e6bd0b40d86aef4c42
parente5b86c93b66b5caeb25a65bae26b04fc7a068957 (diff)
downloadpostgresql-226bc87c2da98ebd9ac08d1677961cb5e7ea4e5a.tar.gz
Improve reporting of newlocale() failures in CREATE COLLATION.
The standardized errno code for "no such locale" failures is ENOENT, which we were just reporting at face value, viz "No such file or directory". Per gripe from Thom Brown, this might confuse users, so add an errdetail message to clarify what it means. Also, report newlocale() failures as ERRCODE_INVALID_PARAMETER_VALUE rather than using errcode_for_file_access(), since newlocale()'s errno values aren't necessarily tied directly to file access failures.
-rw-r--r--src/backend/utils/adt/pg_locale.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index ad99ad0c34..0491df1839 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -707,8 +707,7 @@ cache_locale_time(void)
* otherwise returns the pointer to a static area which
* contains the iso formatted locale name.
*/
-static
-char *
+static char *
IsoLocaleName(const char *winlocname)
{
#if (_MSC_VER >= 1400) /* VC8.0 or later */
@@ -937,6 +936,27 @@ lc_ctype_is_c(Oid collation)
}
+/* simple subroutine for reporting errors from newlocale() */
+static void
+report_newlocale_failure(const char *localename)
+{
+ /* copy errno in case one of the ereport auxiliary functions changes it */
+ int save_errno = errno;
+
+ /*
+ * ENOENT means "no such locale", not "no such file", so clarify that
+ * errno with an errdetail message.
+ */
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("could not create locale \"%s\": %m",
+ localename),
+ (save_errno == ENOENT ?
+ errdetail("The operating system could not find any locale data for the locale name \"%s\".",
+ localename) : 0)));
+}
+
+
/*
* Create a locale_t from a collation OID. Results are cached for the
* lifetime of the backend. Thus, do not free the result with freelocale().
@@ -995,10 +1015,7 @@ pg_newlocale_from_collation(Oid collid)
result = _create_locale(LC_ALL, collcollate);
#endif
if (!result)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not create locale \"%s\": %m",
- collcollate)));
+ report_newlocale_failure(collcollate);
}
else
{
@@ -1008,16 +1025,10 @@ pg_newlocale_from_collation(Oid collid)
loc1 = newlocale(LC_COLLATE_MASK, collcollate, NULL);
if (!loc1)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not create locale \"%s\": %m",
- collcollate)));
+ report_newlocale_failure(collcollate);
result = newlocale(LC_CTYPE_MASK, collctype, loc1);
if (!result)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not create locale \"%s\": %m",
- collctype)));
+ report_newlocale_failure(collctype);
#else
/*