-
Notifications
You must be signed in to change notification settings - Fork 30.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
Truncated error messages produced by WinapiErrnoException #23191
Labels
help wanted
Issues that need assistance from volunteers or PRs that need help to proceed.
windows
Issues and PRs related to the Windows platform.
Comments
TanninOne
added a commit
to Nexus-Mods/node-winapi-bindings
that referenced
this issue
Oct 1, 2018
this was caused by a bug in node presumably, see nodejs/node#23191
/cc @nodejs/platform-windows |
jasnell
added
help wanted
Issues that need assistance from volunteers or PRs that need help to proceed.
windows
Issues and PRs related to the Windows platform.
labels
Jun 26, 2020
huseyinacacak-janea
added a commit
to JaneaSystems/node
that referenced
this issue
Oct 1, 2024
huseyinacacak-janea
added a commit
to JaneaSystems/node
that referenced
this issue
Oct 1, 2024
huseyinacacak-janea
added a commit
to JaneaSystems/node
that referenced
this issue
Oct 2, 2024
huseyinacacak-janea
added a commit
to JaneaSystems/node
that referenced
this issue
Oct 14, 2024
aduh95
pushed a commit
that referenced
this issue
Oct 19, 2024
Fixes: #23191 PR-URL: #55207 Reviewed-By: Luigi Pinca <[email protected]>
louwers
pushed a commit
to louwers/node
that referenced
this issue
Nov 2, 2024
Fixes: nodejs#23191 PR-URL: nodejs#55207 Reviewed-By: Luigi Pinca <[email protected]>
tpoisseau
pushed a commit
to tpoisseau/node
that referenced
this issue
Nov 21, 2024
Fixes: nodejs#23191 PR-URL: nodejs#55207 Reviewed-By: Luigi Pinca <[email protected]>
ruyadorno
pushed a commit
that referenced
this issue
Nov 27, 2024
Fixes: #23191 PR-URL: #55207 Reviewed-By: Luigi Pinca <[email protected]>
marco-ippolito
pushed a commit
that referenced
this issue
Jan 22, 2025
Fixes: #23191 PR-URL: #55207 Reviewed-By: Luigi Pinca <[email protected]>
marco-ippolito
pushed a commit
that referenced
this issue
Jan 22, 2025
Fixes: #23191 PR-URL: #55207 Reviewed-By: Luigi Pinca <[email protected]>
marco-ippolito
pushed a commit
that referenced
this issue
Jan 24, 2025
Fixes: #23191 PR-URL: #55207 Reviewed-By: Luigi Pinca <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
help wanted
Issues that need assistance from volunteers or PRs that need help to proceed.
windows
Issues and PRs related to the Windows platform.
I'm writing a native extension and trying to throw exceptions using WinapiErrnoException but the error messages I get are truncated to only the first letter (so instead of "Access Denied" the error message is "A")
I believe I have tracked the error to https://github.com/nodejs/node/blob/master/src/exceptions.cc where it uses FormatMessage to generate a localised error message from an error code like this:
Now FormatMessage is just a macro that resolves to FormatMessageA on ansi builds and FormatMessageW on wide character/unicode builds. LPTSTR is also a macro that resolves to "char*" on ansi builds and "wchar_t*" on wide character builds.
So I can't be sure but I assume node is built with unicode support so the cast of char* to LPTSTR is invalid as the buffer produced by FormatMessage will be UTF-16 encoded.
This would explain why I get only the first character, as in an english text utf-16 encoded every second byte would be 0x00.
The simplest solution would be to swap FormatMessage for FormatMessageA to explicitly use the ansi variant but the correct solution (for proper localization) would be to change the function to actually use char*/wchar_t* appropriately and then convert to utf-8.
Now I will admit I feel a bit stupid writing this because I can't believe I'd be the first person to notice this if it was true so I'm sure someone will tell me how that's not it and the code actually works as intended - but I don't see how. At the very least the use of the cast from char* to LPTSTR is technically incorrect.
The text was updated successfully, but these errors were encountered: