cwdick: add better error messages on js bundle downloads

Reviewed By: foghina

Differential Revision: D2845168

fb-gh-sync-id: 4566eeff0181d5ae6045e7aeaf00b91579a01feb
This commit is contained in:
Charles Dick 2016-02-08 03:17:10 -08:00 committed by facebook-github-bot-6
parent 577206fe51
commit 81dc884b2a
4 changed files with 23 additions and 17 deletions

View File

@ -22,24 +22,16 @@ import org.json.JSONException;
import org.json.JSONObject;
/**
* Tracks errors connecting to or received from the debug derver.
* The debug server returns errors as json objects. This exception represents that error.
*/
public class DebugServerException extends IOException {
public final String description;
public final String fileName;
public final int lineNumber;
public final int column;
private DebugServerException(String description, String fileName, int lineNumber, int column) {
this.description = description;
this.fileName = fileName;
this.lineNumber = lineNumber;
this.column = column;
super(description + "\n at " + fileName + ":" + lineNumber + ":" + column);
}
public String toReadableMessage() {
return description + "\n at " + fileName + ":" + lineNumber + ":" + column;
public DebugServerException(String description) {
super(description);
}
/**

View File

@ -13,6 +13,7 @@ import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
@ -177,7 +178,7 @@ public class DevServerHelper {
final String jsModulePath,
final File outputFile) {
final String bundleURL = createBundleURL(getDebugServerHost(), jsModulePath, getDevMode(), getHMR());
Request request = new Request.Builder()
final Request request = new Request.Builder()
.url(bundleURL)
.build();
mDownloadBundleFromURLCall = Assertions.assertNotNull(mClient.newCall(request));
@ -191,7 +192,15 @@ public class DevServerHelper {
}
mDownloadBundleFromURLCall = null;
callback.onFailure(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");
callback.onFailure(new DebugServerException(sb.toString()));
}
@Override
@ -210,7 +219,12 @@ public class DevServerHelper {
if (debugServerException != null) {
callback.onFailure(debugServerException);
} else {
callback.onFailure(new IOException("Unexpected response code: " + response.code()));
StringBuilder sb = new StringBuilder();
sb.append("The development server returned response error code: ").append(response.code()).append("\n\n")
.append("URL: ").append(request.urlString()).append("\n\n")
.append("Body:\n")
.append(body);
callback.onFailure(new DebugServerException(sb.toString()));
}
return;
}

View File

@ -633,7 +633,7 @@ public class DevSupportManagerImpl implements DevSupportManager {
public void run() {
if (cause instanceof DebugServerException) {
DebugServerException debugServerException = (DebugServerException) cause;
showNewJavaError(debugServerException.description, cause);
showNewJavaError(debugServerException.getMessage(), cause);
} else {
showNewJavaError(
mApplicationContext.getString(R.string.catalyst_jsload_error),

View File

@ -13,7 +13,7 @@
<string name="catalyst_settings_title" project="catalyst" translatable="false">Catalyst Dev Settings</string>
<string name="catalyst_jsload_title" project="catalyst" translatable="false">Please wait…</string>
<string name="catalyst_jsload_message" project="catalyst" translatable="false">Fetching JS bundle</string>
<string name="catalyst_jsload_error" project="catalyst" translatable="false">Unable to download JS bundle from the dev server.\n\nTry the following to fix the issue:\n• Ensure that the packager server is running\n• 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• 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• If your device is on the same Wi-Fi network, set \'Debug server host &amp; 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</string>
<string name="catalyst_jsload_error" project="catalyst" translatable="false">Unable to download JS bundle. Did you forget to start the development server or connect your device?</string>
<string name="catalyst_remotedbg_message" project="catalyst" translatable="false">Connecting to remote debugger</string>
<string name="catalyst_remotedbg_error" project="catalyst" translatable="false">Unable to connect with remote debugger</string>
<string name="catalyst_element_inspector" project="catalyst" translatable="false">Show Inspector</string>