0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 13:09:21 +01:00

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 <luigipinca@gmail.com>
This commit is contained in:
Hüseyin Açacak 2024-10-15 09:41:38 +03:00 committed by GitHub
parent 87da1f3929
commit 51d81466ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 8 deletions

View File

@ -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;

View File

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