Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1e165d0

Browse files
committed
Try to deliver a sane message for _create_locale() failure on Windows.
We were just printing errno, which is certainly not gonna work on Windows. Now, it's not entirely clear from Microsoft's documentation whether _create_locale() adheres to standard Windows error reporting conventions, but let's assume it does and try to map the GetLastError result to an errno. If this turns out not to work, probably the best thing to do will be to assume the error is always ENOENT on Windows. This is a longstanding bug, but given the lack of previous field complaints, I'm not excited about back-patching it. Per report from Murtuza Zabuawala. Discussion: https://postgr.es/m/CAKKotZS-wcDcofXDCH=sidiuajE+nqHn2CGjLLX78anyDmi3gQ@mail.gmail.com
1 parent c1bb787 commit 1e165d0

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/backend/utils/adt/pg_locale.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -1227,13 +1227,18 @@ lc_ctype_is_c(Oid collation)
12271227
static void
12281228
report_newlocale_failure(const char *localename)
12291229
{
1230-
/* copy errno in case one of the ereport auxiliary functions changes it */
1231-
int save_errno = errno;
1230+
int save_errno;
1231+
1232+
/* On Windows, transform _create_locale() error to errno */
1233+
#ifdef WIN32
1234+
_dosmaperr(GetLastError());
1235+
#endif
12321236

12331237
/*
12341238
* ENOENT means "no such locale", not "no such file", so clarify that
12351239
* errno with an errdetail message.
12361240
*/
1241+
save_errno = errno; /* auxiliary funcs might change errno */
12371242
ereport(ERROR,
12381243
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
12391244
errmsg("could not create locale \"%s\": %m",

src/test/regress/expected/collate.out

+3
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,9 @@ CREATE COLLATION mycoll1 FROM "C";
627627
CREATE COLLATION mycoll2 ( LC_COLLATE = "POSIX", LC_CTYPE = "POSIX" );
628628
CREATE COLLATION mycoll3 FROM "default"; -- intentionally unsupported
629629
ERROR: collation "default" cannot be copied
630+
CREATE COLLATION mycoll4 ( LOCALE = "no_such_locale" ); -- fail
631+
ERROR: could not create locale "no_such_locale": No such file or directory
632+
DETAIL: The operating system could not find any locale data for the locale name "no_such_locale".
630633
DROP COLLATION mycoll1;
631634
CREATE TABLE collate_test23 (f1 text collate mycoll2);
632635
DROP COLLATION mycoll2; -- fail

src/test/regress/sql/collate.sql

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ EXPLAIN (COSTS OFF)
234234
CREATE COLLATION mycoll1 FROM "C";
235235
CREATE COLLATION mycoll2 ( LC_COLLATE = "POSIX", LC_CTYPE = "POSIX" );
236236
CREATE COLLATION mycoll3 FROM "default"; -- intentionally unsupported
237+
CREATE COLLATION mycoll4 ( LOCALE = "no_such_locale" ); -- fail
237238

238239
DROP COLLATION mycoll1;
239240
CREATE TABLE collate_test23 (f1 text collate mycoll2);

0 commit comments

Comments
 (0)