From 97a97b3c11df2b9d93d15770f967061eb27ce187 Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Mon, 21 Mar 2016 14:07:09 -0700 Subject: [PATCH] Tweak error message for HMR Summary:The error messages are iOS specific right now. This PR improves them to include the Android bits also. ![screenshot_20160322-000431](https://cloud.githubusercontent.com/assets/1174278/13929839/2bccce5e-efc2-11e5-9db3-f72dcf486412.png) Closes https://github.com/facebook/react-native/pull/6546 Differential Revision: D3077815 Pulled By: martinbigio fb-gh-sync-id: 344430d350023e78bd5fdae923eb4b6ce2924be5 shipit-source-id: 344430d350023e78bd5fdae923eb4b6ce2924be5 --- Libraries/Utilities/HMRClient.js | 28 +++++++++++++++---- .../react/devsupport/DevServerHelper.java | 4 +-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Libraries/Utilities/HMRClient.js b/Libraries/Utilities/HMRClient.js index 03619f60c3ce27..1301c47ecfa768 100644 --- a/Libraries/Utilities/HMRClient.js +++ b/Libraries/Utilities/HMRClient.js @@ -40,18 +40,36 @@ const HMRClient = { const activeWS = new WebSocket(wsUrl); activeWS.onerror = (e) => { - throw new Error( + let error = ( `Hot loading isn't working because it cannot connect to the development server. -Ensure the following: -- Node server is running and available on the same network -- run 'npm start' from react-native root -- Node server URL is correctly set in AppDelegate +Try the following to fix the issue: +- Ensure that the packager server is running and available on the same network` + ); + + if (Platform.OS === 'ios') { + error += ( +` +- Ensure that the Packager server URL is correctly set in AppDelegate` + ); + } else { + error += ( +` +- Ensure that your device/emulator is connected to your machine and has USB debugging enabled - run 'adb devices' to see a list of connected devices +- If you're on a physical device connected to the same machine, run 'adb reverse tcp:8081 tcp:8081' to forward requests from your device +- If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:8081` + ); + } + + error += ( +` URL: ${host}:${port} Error: ${e.message}` ); + + throw new Error(error); }; activeWS.onmessage = ({data}) => { // Moving to top gives errors due to NativeModules not being initialized diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java index d8d802320837b6..78b570e6f3c614 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java @@ -194,12 +194,12 @@ public void onFailure(Request request, IOException e) { StringBuilder sb = new StringBuilder(); sb.append("Could not connect to development server.\n\n") - .append("URL: ").append(request.urlString()).append("\n\n") .append("Try the following to fix the issue:\n") .append("\u2022 Ensure that the packager server is running\n") .append("\u2022 Ensure that your device/emulator is connected to your machine and has USB debugging enabled - run 'adb devices' to see a list of connected devices\n") .append("\u2022 If you're on a physical device connected to the same machine, run 'adb reverse tcp:8081 tcp:8081' to forward requests from your device\n") - .append("\u2022 If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:8081"); + .append("\u2022 If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:8081\n\n") + .append("URL: ").append(request.urlString()); callback.onFailure(new DebugServerException(sb.toString())); }