Skip to content

Commit c00173f

Browse files
vzaidmanmeta-codesync[bot]
authored andcommitted
add debug statements to debugger shell launching path (#54929)
Summary: Pull Request resolved: #54929 There's a bug in Node.JS: nodejs/node#51018 where spawning a process on Windows with detached mode and unref will not actually inherit stdio. You need to manually pipe these to get to see stdout and stderr. It works well on MacOS though. Changelog: [Internal] Reviewed By: huntie Differential Revision: D88955169 fbshipit-source-id: cba661b13d8636d4d52122fe024f876300d4af1f
1 parent bdcda15 commit c00173f

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

packages/debugger-shell/src/node/index.flow.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from './private/LaunchUtils';
1515

1616
const {spawn} = require('cross-spawn');
17+
const debug = require('debug')('Metro:Debugger:DebuggerShell');
1718
const path = require('path');
1819

1920
// The 'prebuilt' flavor will use the prebuilt shell binary (and the JavaScript embedded in it).
@@ -55,36 +56,59 @@ async function unstable_spawnDebuggerShellWithArgs(
5556
...env
5657
} = process.env;
5758
const child = spawn(binaryPath, [...baseArgs, ...args], {
58-
stdio: 'inherit',
59+
stdio: ['ignore', 'pipe', 'pipe'],
5960
windowsHide: true,
6061
detached: mode === 'detached',
6162
env,
6263
});
6364
if (mode === 'detached') {
6465
child.on('spawn', () => {
66+
debug('Debugger spawned in detached mode');
6567
resolve();
6668
});
67-
child.on('close', (code: number) => {
69+
child.on('close', (code: number, signal) => {
70+
debug('Debugger closed with code %s and signal %s', code, signal);
6871
if (code !== 0) {
72+
console.error(
73+
'Debugger closed with code %s and signal %s',
74+
code,
75+
signal,
76+
);
6977
reject(
7078
new Error(
7179
`Failed to open debugger shell: exited with code ${code}`,
7280
),
7381
);
7482
}
7583
});
84+
child.on('error', error => {
85+
debug('Debugger shell encountered error: %s', error);
86+
reject(error);
87+
});
88+
child.stdout.on('data', data =>
89+
console.debug('[DebuggerShell stdout] ' + String(data)),
90+
);
91+
child.stderr.on('data', data =>
92+
console.debug('[DebuggerShell stderr] ' + String(data)),
93+
);
7694
child.unref();
7795
} else if (mode === 'syncThenExit') {
7896
child.on('close', function (code, signal) {
97+
debug('Debugger closed with code %s and signal %s', code, signal);
7998
if (code === null) {
80-
console.error('Debugger shell exited with signal', signal);
99+
console.error(
100+
'Debugger closed with code %s and signal %s',
101+
code,
102+
signal,
103+
);
81104
process.exit(1);
82105
}
83106
process.exit(code);
84107
});
85108

86109
const handleTerminationSignal = function (signal: string) {
87110
process.on(signal, function signalHandler() {
111+
debug('The Signal %s received. killing debugger', signal);
88112
if (!child.killed) {
89113
child.kill(signal);
90114
}

0 commit comments

Comments
 (0)