From 95c8b00becd852a42d0606a5a656c2ce59a0cee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20A=C3=A7acak?= Date: Tue, 1 Oct 2024 10:16:35 +0300 Subject: [PATCH] src: fix winapi_strerror error string Fixes: https://github.com/nodejs/node/issues/23191 --- src/api/exceptions.cc | 4 +-- test/parallel/test-print-GH-23191.js | 43 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 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..a2935e03b072ff 100644 --- a/src/api/exceptions.cc +++ b/src/api/exceptions.cc @@ -157,12 +157,12 @@ 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 | + FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, errorno, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - reinterpret_cast(&errmsg), + reinterpret_cast(&errmsg), 0, nullptr); diff --git a/test/parallel/test-print-GH-23191.js b/test/parallel/test-print-GH-23191.js new file mode 100644 index 00000000000000..56fe4677e8d1b4 --- /dev/null +++ b/test/parallel/test-print-GH-23191.js @@ -0,0 +1,43 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +'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()); +}