Skip to content

Commit 565a983

Browse files
src: fix winapi_strerror error string
Fixes: #23191
1 parent d17fefc commit 565a983

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/api/exceptions.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ Local<Value> UVException(Isolate* isolate,
157157
static const char* winapi_strerror(const int errorno, bool* must_free) {
158158
char* errmsg = nullptr;
159159

160-
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
161-
FORMAT_MESSAGE_IGNORE_INSERTS,
162-
nullptr,
163-
errorno,
164-
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
165-
reinterpret_cast<LPTSTR>(&errmsg),
166-
0,
167-
nullptr);
160+
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
161+
FORMAT_MESSAGE_IGNORE_INSERTS,
162+
nullptr,
163+
errorno,
164+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
165+
reinterpret_cast<LPSTR>(&errmsg),
166+
0,
167+
nullptr);
168168

169169
if (errmsg) {
170170
*must_free = true;

test/parallel/test-print-GH-23191.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
const common = require('../common');
3+
const { strictEqual } = require('assert');
4+
5+
// Ref: https://github.com/nodejs/node/issues/23191
6+
// This test is specific to Windows.
7+
8+
async function testDebugPrint() {
9+
10+
const child = require('child_process');
11+
const cp = child.spawnSync(process.execPath,
12+
['-e', 'console.log("Hello World");']);
13+
try {
14+
process._debugProcess(cp.pid);
15+
} catch (error) {
16+
strictEqual(error.message, 'The parameter is incorrect.');
17+
}
18+
}
19+
20+
if (common.isWindows) {
21+
testDebugPrint().then(common.mustCall());
22+
}

0 commit comments

Comments
 (0)