Skip to content

Commit fdc4ef1

Browse files
robhoganfacebook-github-bot
authored andcommittedMay 19, 2022
InspectorProxy: Don't pass an Error object to socket.close()
Summary: Currently our error handling for websocket connections in `InspectorProxy` passes whatever is thrown as an "error explanation" to `socket.close()`. This argument expects `string | undefined` (NB `null` is also invalid) In cases where we're catching and passing an `Error`, this causes the socket instance to emit its own `'error'`, which we don't have any listener for, causing a crash. This diff uses `e?.toString() ?? 'Unknown error'` to: - Preserve the current behaviour for raw strings - Show `Error: ${e.message}` when `e instanceof Error` - Show `Unknown error` when `e == null`. Changelog: **Fix:** Prevent `InspectorProxy` connection errors crashing the process. Reviewed By: motiz88 Differential Revision: D36479972 fbshipit-source-id: 622be8c5f6bc516dd3bf9115445c7fca9c841409
1 parent 05c83d7 commit fdc4ef1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed
 

‎packages/metro-inspector-proxy/src/InspectorProxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class InspectorProxy {
177177
});
178178
} catch (e) {
179179
console.error('error', e);
180-
socket.close(INTERNAL_ERROR_CODE, e);
180+
socket.close(INTERNAL_ERROR_CODE, e?.toString() ?? 'Unknown error');
181181
}
182182
});
183183
return wss;
@@ -212,7 +212,7 @@ class InspectorProxy {
212212
device.handleDebuggerConnection(socket, pageId);
213213
} catch (e) {
214214
console.error(e);
215-
socket.close(INTERNAL_ERROR_CODE, e);
215+
socket.close(INTERNAL_ERROR_CODE, e?.toString() ?? 'Unknown error');
216216
}
217217
});
218218
return wss;

0 commit comments

Comments
 (0)
Please sign in to comment.