-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prefer US English for system_category()
messages, fall back to system locale, then ID 0
#5104
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
system_category()
messagessystem_category()
messages, fall back to system locale
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
system_category()
messages, fall back to system localesystem_category()
messages, fall back to system locale, then ID 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
de-DE single-language system with de-DE system locale:
System locale name: "de-DE"
System language ID: 1031 decimal, 0x0407 hex
ERROR_FILE_NOT_FOUND: "Das System kann die angegebene Datei nicht finden."
de-DE single-language system with de-CH system locale:
System locale name: "de-CH"
System language ID: 2055 decimal, 0x0807 hex
ERROR_FILE_NOT_FOUND: "Das System kann die angegebene Datei nicht finden."
This comment was marked as resolved.
This comment was marked as resolved.
As I mentioned in the PR description, we can consider pathological scenarios in the future, if they turn out to happen with any significant frequency. I think I would actually recommend manually |
Fixes #3254, a regression introduced by #2669 in VS 2022 17.3.
😻 Thanks
Thanks to:
FormatMessageA
if the error messages are not available in system locale #3260 inspired this alternative approach,FormatMessageA
if the error messages are not available in system locale #3260 (comment)),FormatMessageA
if the error messages are not available in system locale #3260 (comment)),std::system_category
returns "unknown error" if system locale is not en-US #3254 (comment)),📜 Overview
The original (pre-#2669) strategy of using language ID 0 to request
FormatMessageA
's multi-step behavior was problematic because it tries the user's locale before the system locale, but the user's locale might not result in an intelligiblechar*
, so we could get strings filled with question marks.The status quo (post-#2669) strategy of using the system locale was problematic because the system locale might not have error message strings. For example, this is the case when the system locale is English (United Kingdom).
We also have to worry about single-language installations of Windows, which don't have US English error message strings.
After considering all of these scenarios and talking to contributors, I believe that the best strategy is to attempt 3 things in this order:
generic_category()
, as my new comment explains.winnt.h
) macroMAKELANGID
to construct it, I'm just hardcoding the language ID.main
(i.e. what <system_error>: explicitly pass the system locale ID for system_category messages #2669 did).main
does if we can't get the system locale, and what we always did before <system_error>: explicitly pass the system locale ID for system_category messages #2669, so we have many years of experience with this codepath.char*
), well, we tried. At this time, I don't want to explore novel logic like callingFormatMessageW
and converting to UTF-8. If this scenario turns out to occur in practice, we can explore changes in the future.💻 Test Code
🧑🔬 Initial Testing
On a Dev Box (Win11 24H2, en-US), I left the "Windows display language" unchanged:
Settings > Time & language > Language & region > Windows display language > English (United States)
But I changed the system locale to en-GB and rebooted:
Settings > Time & language > Language & region > Administrative language settings > Change system locale... > English (United Kingdom)
Before this PR:
After this PR:
Retested with the 3-step loop successfully.
🧪 More Testing
Then, I verified that this PR isn't causing #2451 to reappear (this was the original bug that #2669 attempted to fix).
Following #2451 (comment), I set my Dev Box's Windows display language to Chinese (installing all of the language pack stuff) and the system locale back to en-US. Then, after slightly altering the repro to use
format()
instead ofprint()
, I verified that the side-by-side install of VS 2019 16.11 reproed the original bug, VS 2022 17.13 Preview 2 (internal) worked with #2669's changes (the status quo ofmain
), and this PR worked as well.Retested with the 3-step loop successfully.
1️⃣ Single-Language OS Testing
In #5104 (review), @muellerj2 verified that
succeed with German strings. These are exercising the system locale and ID 0 fallbacks, respectively.