Skip to content

Commit 1fe7a13

Browse files
committed
Clarify non-fatal React Native DevTools preparation errors
When preparing the standalone React Native DevTools shell throws (e.g. the Electron binary fails to launch on some Linux setups), the dev server logged "An unknown error occurred while installing React Native DevTools.." as an error. This is not fatal: /open-debugger falls back to a browser window. - Give the catch-all unexpected_error result a humanReadableMessage that says a fallback is used, consistent with the other failure codes. - Log unexpected_error as a warning, like the other non-fatal failure codes, and drop the duplicated trailing period. Addresses #54906
1 parent 024b474 commit 1fe7a13

4 files changed

Lines changed: 72 additions & 4 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
* @oncall react_native
10+
*/
11+
12+
jest.mock('../private/LaunchUtils', () => ({
13+
prepareDebuggerShellFromDotSlashFile: jest.fn(() =>
14+
Promise.reject(new Error('spawn failed')),
15+
),
16+
}));
17+
18+
const {unstable_prepareDebuggerShell} = require('../../');
19+
20+
describe('unstable_prepareDebuggerShell', () => {
21+
test('returns a human readable message for unexpected errors', async () => {
22+
const result = await unstable_prepareDebuggerShell({flavor: 'prebuilt'});
23+
24+
expect(result.code).toBe('unexpected_error');
25+
expect(result.verboseInfo).toBe('spawn failed');
26+
expect(result.humanReadableMessage).toContain(
27+
'Using a fallback version instead',
28+
);
29+
});
30+
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ async function unstable_prepareDebuggerShell({
175175
} catch (e) {
176176
return {
177177
code: 'unexpected_error',
178+
humanReadableMessage:
179+
'An unexpected error occurred while preparing React Native DevTools. ' +
180+
'Using a fallback version instead.',
178181
verboseInfo: e.message,
179182
};
180183
}

‎packages/dev-middleware/src/__tests__/StandaloneFuseboxShell-test.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,38 @@ describe('enableStandaloneFuseboxShell experiment', () => {
232232
});
233233
});
234234
});
235+
236+
describe('preparation failure logging', () => {
237+
const logger = {
238+
error: jest.fn(),
239+
info: jest.fn(),
240+
warn: jest.fn(),
241+
};
242+
const {ToolLauncherWithFuseboxShell} = setupToolLauncherWithFuseboxShell(
243+
() =>
244+
Promise.resolve({
245+
code: 'unexpected_error',
246+
verboseInfo: 'LaunchProcess: failed to execvp',
247+
}),
248+
);
249+
const server = withServerForEachTest({
250+
logger,
251+
unstable_toolLauncher: ToolLauncherWithFuseboxShell,
252+
unstable_experiments: {
253+
enableStandaloneFuseboxShell: true,
254+
},
255+
});
256+
257+
test('logs an unexpected error as a non-fatal warning', async () => {
258+
// Access the server to ensure the dev middleware has been created
259+
expect(server.serverBaseUrl).toBeDefined();
260+
await jest.runOnlyPendingTimersAsync();
261+
262+
expect(logger.error).not.toHaveBeenCalled();
263+
expect(logger.warn).toHaveBeenCalledTimes(1);
264+
const [message] = logger.warn.mock.calls[0];
265+
expect(message).toContain('Using a fallback version instead');
266+
expect(message).toContain('LaunchProcess: failed to execvp');
267+
});
268+
});
235269
});

‎packages/dev-middleware/src/createDevMiddleware.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,16 @@ function createWrappedEventReporter(
177177
case 'not_implemented':
178178
break;
179179
case 'unexpected_error': {
180+
// Preparation failures are not fatal: the debugger falls back to
181+
// opening in a browser window, so log a warning, not an error.
180182
let message =
181183
event.result.humanReadableMessage ??
182-
'An unknown error occurred while installing React Native DevTools.';
184+
'An unknown error occurred while installing React Native DevTools. ' +
185+
'Using a fallback version instead.';
183186
if (event.result.verboseInfo != null) {
184187
message += ` Details:\n\n${event.result.verboseInfo}`;
185-
} else {
186-
message += '.';
187188
}
188-
logger?.error(message);
189+
logger?.warn(message);
189190
break;
190191
}
191192
case 'possible_corruption':

0 commit comments

Comments
 (0)