Skip to content
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

src: fix winapi_strerror error string #55207

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/api/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ Local<Value> UVException(Isolate* isolate,
static const char* winapi_strerror(const int errorno, bool* must_free) {
char* errmsg = nullptr;

FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr,
errorno,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPTSTR>(&errmsg),
0,
nullptr);
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr,
errorno,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPSTR>(&errmsg),
0,
nullptr);

if (errmsg) {
*must_free = true;
Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-debug-process.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const child = require('child_process');

if (!common.isWindows) {
common.skip('This test is specific to Windows to test winapi_strerror');
}

// Ref: https://github.com/nodejs/node/issues/23191
// This test is specific to Windows.

const cp = child.spawn('pwd');

cp.on('exit', common.mustCall(function() {
try {
process._debugProcess(cp.pid);
} catch (error) {
assert.strictEqual(error.message, 'The system cannot find the file specified.');
}
}));
Loading