Skip to content

Commit bc164d2

Browse files
Preserve the original Fantom spawn error
## Summary: Fixes #60059. Fantom throws while reading stdout if a child process cannot start. Treat missing stdout as empty so the caller gets the original spawn error, just as it already does for stderr. Thanks @YevheniiKotyrlo for reporting the issue and providing the reproducer. Codex helped implement and verify the change. ## Changelog: [INTERNAL] [FIXED] - Preserve the original process launch error in Fantom. ## Test Plan: - `yarn test --ci --runInBand private/react-native-fantom/runner/__tests__` on Windows: 11 tests passed. The missing-executable case fails on main and now reports ENOENT. The successful subprocess still returns both output streams. - ESLint and Prettier passed for both changed files. Differential Revision: D132612487 Pull Request resolved: #60088
1 parent fbb5319 commit bc164d2

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
import {getDebugInfoFromCommandResult, runCommandSync} from '../utils';
12+
import path from 'node:path';
13+
14+
describe('runCommandSync', () => {
15+
it('preserves the spawn error when the command cannot start', () => {
16+
const command = path.join(__dirname, 'nonexistent-fantom-executable');
17+
const result = runCommandSync(command, [], {});
18+
19+
expect(result).toMatchObject({
20+
error: {code: 'ENOENT'},
21+
status: null,
22+
stdout: '',
23+
stderr: '',
24+
});
25+
expect(getDebugInfoFromCommandResult(result)).toContain('ENOENT');
26+
});
27+
28+
it('returns output from a command that starts', () => {
29+
const result = runCommandSync(
30+
process.execPath,
31+
['-e', 'process.stdout.write("output"); process.stderr.write("error")'],
32+
{},
33+
);
34+
35+
expect(result).toMatchObject({
36+
status: 0,
37+
stdout: 'output',
38+
stderr: 'error',
39+
});
40+
expect(result.error).toBeUndefined();
41+
});
42+
});

‎private/react-native-fantom/runner/utils.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export function runCommandSync(
254254
status: result.status,
255255
signal: result.signal,
256256
error: result.error,
257-
stdout: result.stdout.toString(),
257+
stdout: result.stdout?.toString() ?? '',
258258
stderr: result.stderr?.toString() ?? '',
259259
};
260260
}

0 commit comments

Comments
 (0)