Skip to content

Commit

Permalink
src: fix winapi_strerror error string
Browse files Browse the repository at this point in the history
Fixes: #23191
  • Loading branch information
huseyinacacak-janea committed Oct 1, 2024
1 parent d17fefc commit 565a983
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
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
22 changes: 22 additions & 0 deletions test/parallel/test-print-GH-23191.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';
const common = require('../common');
const { strictEqual } = require('assert');

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

async function testDebugPrint() {

const child = require('child_process');
const cp = child.spawnSync(process.execPath,
['-e', 'console.log("Hello World");']);
try {
process._debugProcess(cp.pid);
} catch (error) {
strictEqual(error.message, 'The parameter is incorrect.');
}
}

if (common.isWindows) {
testDebugPrint().then(common.mustCall());
}

0 comments on commit 565a983

Please sign in to comment.