From d8c6d703ffcb7a17f70042ffef13dab2ae9ecc08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20A=C3=A7acak?= Date: Wed, 2 Oct 2024 09:48:29 +0300 Subject: [PATCH] src: fix winapi_strerror error string Fixes: https://github.com/nodejs/node/issues/23191 --- src/api/exceptions.cc | 16 ++++++++-------- test/parallel/test-print-GH-23191.js | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 test/parallel/test-print-GH-23191.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-print-GH-23191.js b/test/parallel/test-print-GH-23191.js new file mode 100644 index 00000000000000..97677eb468bc67 --- /dev/null +++ b/test/parallel/test-print-GH-23191.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(code) { + try { + process._debugProcess(cp.pid); + } catch (error) { + assert.strictEqual(error.message, 'The system cannot find the file specified.'); + } +}));