From 964530c7c29c166ff316a2132f17dcaa9668dd48 Mon Sep 17 00:00:00 2001 From: Yuri Kulikov Date: Fri, 15 Mar 2019 21:57:14 +0300 Subject: [PATCH] Handle codepush.json parsing exception (#1540) --- .../java/com/microsoft/codepush/react/CodePush.java | 10 +++++++++- .../microsoft/codepush/react/CodePushNativeModule.java | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java index 99d56e674..3dfcd3ec1 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java @@ -213,7 +213,15 @@ public String getJSBundleFileInternal(String assetsBundleFileName) { this.mAssetsBundleFileName = assetsBundleFileName; String binaryJsBundleUrl = CodePushConstants.ASSETS_BUNDLE_PREFIX + assetsBundleFileName; - String packageFilePath = mUpdateManager.getCurrentPackageBundlePath(this.mAssetsBundleFileName); + String packageFilePath = null; + try { + packageFilePath = mUpdateManager.getCurrentPackageBundlePath(this.mAssetsBundleFileName); + } catch (CodePushMalformedDataException e) { + // We need to recover the app in case 'codepush.json' is corrupted + CodePushUtils.log(e.getMessage()); + clearUpdates(); + } + if (packageFilePath == null) { // There has not been any downloaded updates. CodePushUtils.logBundleUrl(binaryJsBundleUrl); diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java index f19c7c2e7..32e02e81a 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java @@ -349,6 +349,11 @@ protected Void doInBackground(Void... params) { CodePushUtils.setJSONValueForKey(currentPackage, "isPending", currentUpdateIsPending); promise.resolve(CodePushUtils.convertJsonObjectToWritable(currentPackage)); } + } catch (CodePushMalformedDataException e) { + // We need to recover the app in case 'codepush.json' is corrupted + CodePushUtils.log(e.getMessage()); + clearUpdates(); + promise.resolve(null); } catch(CodePushUnknownException e) { CodePushUtils.log(e); promise.reject(e);