From 51d81466efc00417711558a08d0ff4206d8bf174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20A=C3=A7acak?= <110401522+huseyinacacak-janea@users.noreply.github.com> Date: Tue, 15 Oct 2024 09:41:38 +0300 Subject: [PATCH] src: fix winapi_strerror error string Fixes: https://github.com/nodejs/node/issues/23191 PR-URL: https://github.com/nodejs/node/pull/55207 Reviewed-By: Luigi Pinca --- src/api/exceptions.cc | 16 ++++++++-------- test/parallel/test-debug-process.js | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 test/parallel/test-debug-process.js diff --git a/src/api/exceptions.cc b/src/api/exceptions.cc index 1b9b308ad89fc6..871fe78de95154 100644 --- a/src/api/exceptions.cc +++ b/src/api/exceptions.cc @@ -157,14 +157,14 @@ Local 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(&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(&errmsg), + 0, + nullptr); if (errmsg) { *must_free = true; diff --git a/test/parallel/test-debug-process.js b/test/parallel/test-debug-process.js new file mode 100644 index 00000000000000..0d10a15e2eefa0 --- /dev/null +++ b/test/parallel/test-debug-process.js @@ -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.'); + } +}));