Skip to content

Commit 9b4be02

Browse files
vzaidmanfacebook-github-bot
authored andcommitted
standardize error messages thrown from inspector proxy when connection is closed to debugger (facebook#51227)
Summary: Pull Request resolved: facebook#51227 Standardize error messages thrown from inspector proxy when connection is closed to debugger and link to where they are used in `react-native-devtools-frontend` Changelog: [Internal] Reviewed By: huntie Differential Revision: D74484316 fbshipit-source-id: 7885bc5ea41397539814f97d764c9a376ef50eaa
1 parent d06c288 commit 9b4be02

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

packages/dev-middleware/src/inspector-proxy/Device.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ const WS_CLOSURE_CODE = {
4444
};
4545

4646
export const WS_CLOSE_REASON = {
47-
PAGE_NOT_FOUND: 'Debugger Page Not Found',
48-
DEVICE_DISCONNECTED: 'Corresponding Device Disconnected',
49-
RECREATING_DEVICE: 'Recreating Device Connection',
50-
RECREATING_DEBUGGER: 'Recreating Debugger Connection',
47+
PAGE_NOT_FOUND: '[PAGE_NOT_FOUND] Debugger Page Not Found',
48+
CONNECTION_LOST: '[CONNECTION_LOST] Connection lost to corresponding device',
49+
RECREATING_DEVICE: '[RECREATING_DEVICE] Recreating Device Connection',
50+
RECREATING_DEBUGGER: '[RECREATING_DEBUGGER] Recreating Debugger Connection',
5151
};
5252

5353
// Prefix for script URLs that are alphanumeric IDs. See comment in #processMessageFromDeviceLegacy method for
@@ -219,7 +219,7 @@ export default class Device {
219219
// Device disconnected - close debugger connection.
220220
this.#terminateDebuggerConnection(
221221
WS_CLOSURE_CODE.NORMAL,
222-
WS_CLOSE_REASON.DEVICE_DISCONNECTED,
222+
WS_CLOSE_REASON.CONNECTION_LOST,
223223
);
224224
clearInterval(this.#pagesPollingIntervalId);
225225
}

packages/dev-middleware/src/inspector-proxy/InspectorProxy.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ const MIN_EVENT_LOOP_DELAY_PERCENT_TO_REPORT = 20;
4747

4848
const INTERNAL_ERROR_CODE = 1011;
4949

50+
// should be aligned with
51+
// https://github.com/facebook/react-native-devtools-frontend/blob/fa273092fbc8edc94d4a0a3621735f4677a99ba8/front_end/ui/legacy/components/utils/TargetDetachedDialog.ts#L50
52+
const INTERNAL_ERROR_MESSAGES = {
53+
UREGISTERED_DEVICE:
54+
'[UREGISTERED_DEVICE] Debugger connection attempted for a device that was not registered',
55+
INCORRECT_URL:
56+
'[INCORRECT_URL] Incorrect URL - device and page IDs must be provided',
57+
};
58+
5059
export type GetPageDescriptionsConfig = {
5160
requestorRelativeBaseUrl: URL,
5261
logNoPagesForConnectedDevice?: boolean,
@@ -507,13 +516,11 @@ export default class InspectorProxy implements InspectorProxyQueries {
507516

508517
try {
509518
if (deviceId == null || pageId == null) {
510-
throw new Error('Incorrect URL - must provide device and page IDs');
519+
throw new Error(INTERNAL_ERROR_MESSAGES.INCORRECT_URL);
511520
}
512521

513522
if (device == null) {
514-
throw new Error(
515-
'Debugger connection attempted for a non registered device',
516-
);
523+
throw new Error(INTERNAL_ERROR_MESSAGES.UREGISTERED_DEVICE);
517524
}
518525

519526
this.#logger?.info(

0 commit comments

Comments
 (0)