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.'); + } +}));