From 10cb072fc388b758e924abbf0f1fefe1b1943de7 Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Wed, 26 Feb 2025 20:40:10 +0800 Subject: [PATCH] improve errorUpdate message --- Example/testHotUpdate/bun.lock | 4 ++-- Example/testHotUpdate/package.json | 2 +- .../modules/update/DownloadTask.java | 20 +++++++++---------- package.json | 2 +- src/client.ts | 20 +++++++++++++------ 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Example/testHotUpdate/bun.lock b/Example/testHotUpdate/bun.lock index 609752b..7ff5ab2 100644 --- a/Example/testHotUpdate/bun.lock +++ b/Example/testHotUpdate/bun.lock @@ -12,7 +12,7 @@ "react-native-paper": "^5.13.1", "react-native-safe-area-context": "^5.2.0", "react-native-svg": "^15.11.1", - "react-native-update": "^10.25.0", + "react-native-update": "^10.25.2", "react-native-vector-icons": "^10.2.0", }, "devDependencies": { @@ -1434,7 +1434,7 @@ "react-native-svg": ["react-native-svg@15.11.1", "", { "dependencies": { "css-select": "^5.1.0", "css-tree": "^1.1.3", "warn-once": "0.1.1" }, "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-Qmwx/yJKt+AHUr4zjxx/Q69qwKtRfr1+uIfFMQoq3WFRhqU76aL9db1DyvPiY632DAsVGba1pHf92OZPkpjrdQ=="], - "react-native-update": ["react-native-update@10.25.0", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-4EYcYZFMhd/VMk9EwND4N2NOBZJYTksvbLdGTgqwYA1NT4IUmBgTFGeeng8GzazOqh4yP0tlW98zpW+67DEZsg=="], + "react-native-update": ["react-native-update@10.25.2", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-HI44TvCdkwXDbIzMKIcz4BK1my+dQYZz3GbiJJiv5/9Sqfl/uiLSr/Z9xUjX4O7G28N206KItORj7YK6yt/66w=="], "react-native-url-polyfill": ["react-native-url-polyfill@2.0.0", "", { "dependencies": { "whatwg-url-without-unicode": "8.0.0-3" }, "peerDependencies": { "react-native": "*" } }, "sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA=="], diff --git a/Example/testHotUpdate/package.json b/Example/testHotUpdate/package.json index a871b75..c5adce0 100644 --- a/Example/testHotUpdate/package.json +++ b/Example/testHotUpdate/package.json @@ -23,7 +23,7 @@ "react-native-paper": "^5.13.1", "react-native-safe-area-context": "^5.2.0", "react-native-svg": "^15.11.1", - "react-native-update": "^10.25.0", + "react-native-update": "^10.25.2", "react-native-vector-icons": "^10.2.0" }, "devDependencies": { diff --git a/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java b/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java index d37eb56..b5671c9 100644 --- a/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java +++ b/android/src/main/java/cn/reactnative/modules/update/DownloadTask.java @@ -49,7 +49,7 @@ class DownloadTask extends AsyncTask { private void removeDirectory(File file) throws IOException { if (UpdateContext.DEBUG) { - Log.d("RNUpdate", "Removing " + file); + Log.d("react-native-update", "Removing " + file); } if (file.isDirectory()) { File[] files = file.listFiles(); @@ -88,7 +88,7 @@ class DownloadTask extends AsyncTask { BufferedSink sink = Okio.buffer(Okio.sink(writePath)); if (UpdateContext.DEBUG) { - Log.d("RNUpdate", "Downloading " + url); + Log.d("react-native-update", "Downloading " + url); } long bytesRead = 0; @@ -98,7 +98,7 @@ class DownloadTask extends AsyncTask { received += bytesRead; sink.emit(); if (UpdateContext.DEBUG) { - Log.d("RNUpdate", "Progress " + received + "/" + contentLength); + Log.d("react-native-update", "Progress " + received + "/" + contentLength); } int percentage = (int)(received * 100.0 / contentLength + 0.5); @@ -115,7 +115,7 @@ class DownloadTask extends AsyncTask { sink.close(); if (UpdateContext.DEBUG) { - Log.d("RNUpdate", "Download finished"); + Log.d("react-native-update", "Download finished"); } } @@ -244,7 +244,7 @@ class DownloadTask extends AsyncTask { if (UpdateContext.DEBUG) { - Log.d("RNUpdate", "Unzip finished"); + Log.d("react-native-update", "Unzip finished"); } } @@ -260,7 +260,7 @@ class DownloadTask extends AsyncTask { File lastTarget = null; for (File target: targets) { if (UpdateContext.DEBUG) { - Log.d("RNUpdate", "Copying from resource " + fn + " to " + target); + Log.d("react-native-update", "Copying from resource " + fn + " to " + target); } if (lastTarget != null) { copyFile(lastTarget, target); @@ -352,7 +352,7 @@ class DownloadTask extends AsyncTask { copyFromResource(copyList); if (UpdateContext.DEBUG) { - Log.d("RNUpdate", "Unzip finished"); + Log.d("react-native-update", "Unzip finished"); } } @@ -418,12 +418,12 @@ class DownloadTask extends AsyncTask { throw new Error("bundle patch not found"); } if (UpdateContext.DEBUG) { - Log.d("RNUpdate", "Unzip finished"); + Log.d("react-native-update", "Unzip finished"); } } private void doCleanUp(DownloadTaskParams param) throws IOException { if (UpdateContext.DEBUG) { - Log.d("RNUpdate", "Start cleaning up"); + Log.d("react-native-update", "Start cleaning up"); } File root = param.unzipDirectory; for (File sub : root.listFiles()) { @@ -499,7 +499,7 @@ class DownloadTask extends AsyncTask { default: break; } - Log.e("pushy", "download task failed", e); + Log.e("react-native-update", "download task failed", e); if (params[0].listener != null) { params[0].listener.onDownloadFailed(e); diff --git a/package.json b/package.json index dfefdc5..9fba462 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-update", - "version": "10.25.2", + "version": "10.25.3", "description": "react-native hot update", "main": "src/index", "scripts": { diff --git a/src/client.ts b/src/client.ts index ff51429..2708d4c 100644 --- a/src/client.ts +++ b/src/client.ts @@ -361,6 +361,7 @@ export class Pushy { let succeeded = ''; this.report({ type: 'downloading' }); let lastError: any; + let errorMessages: string[] = []; const diffUrl = await testUrls(joinUrls(paths, diff)); if (diffUrl) { log('downloading diff'); @@ -372,11 +373,13 @@ export class Pushy { }); succeeded = 'diff'; } catch (e: any) { - lastError = e; + const errorMessage = `diff error: ${e.message}`; + errorMessages.push(errorMessage); + lastError = new Error(errorMessage); if (__DEV__) { succeeded = 'diff'; } else { - log(`diff error: ${e.message}, try pdiff`); + log(errorMessage); } } } @@ -390,11 +393,13 @@ export class Pushy { }); succeeded = 'pdiff'; } catch (e: any) { - lastError = e; + const errorMessage = `pdiff error: ${e.message}`; + errorMessages.push(errorMessage); + lastError = new Error(errorMessage); if (__DEV__) { succeeded = 'pdiff'; } else { - log(`pdiff error: ${e.message}, try full patch`); + log(errorMessage); } } } @@ -408,11 +413,13 @@ export class Pushy { }); succeeded = 'full'; } catch (e: any) { - lastError = e; + const errorMessage = `full patch error: ${e.message}`; + errorMessages.push(errorMessage); + lastError = new Error(errorMessage); if (__DEV__) { succeeded = 'full'; } else { - log(`full patch error: ${e.message}`); + log(errorMessage); } } } @@ -427,6 +434,7 @@ export class Pushy { this.report({ type: 'errorUpdate', data: { newVersion: hash }, + message: errorMessages.join(';'), }); if (lastError) { throw lastError;