From c6d7d1929e6a6db12e80d351eea9361194f843d0 Mon Sep 17 00:00:00 2001 From: Yuri Kulikov Date: Thu, 14 Mar 2019 18:56:46 +0300 Subject: [PATCH] Handle codepush.json parsing exception --- .../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);