From df9499b723fe7a193c343bd46797feaef73aeef9 Mon Sep 17 00:00:00 2001 From: Burning_TNT <88144530+burningtnt@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:23:10 +0800 Subject: [PATCH] Catch Internal Error (#2520) * Catch Internal Error * Fix * Fix I18N --- .../java/org/jackhuang/hmcl/countly/CrashReport.java | 7 +++++++ .../main/java/org/jackhuang/hmcl/ui/CrashWindow.java | 11 +++++++---- .../java/org/jackhuang/hmcl/util/CrashReporter.java | 6 ++---- HMCL/src/main/resources/assets/lang/I18N.properties | 3 ++- .../src/main/resources/assets/lang/I18N_es.properties | 2 +- .../src/main/resources/assets/lang/I18N_ja.properties | 2 +- .../src/main/resources/assets/lang/I18N_ru.properties | 2 +- .../src/main/resources/assets/lang/I18N_zh.properties | 3 ++- .../main/resources/assets/lang/I18N_zh_CN.properties | 3 ++- 9 files changed, 25 insertions(+), 14 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/countly/CrashReport.java b/HMCL/src/main/java/org/jackhuang/hmcl/countly/CrashReport.java index dac5a9b06..75f562a27 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/countly/CrashReport.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/countly/CrashReport.java @@ -29,6 +29,10 @@ public class CrashReport { nonFatal = false; } + public Throwable getThrowable() { + return this.throwable; + } + public CrashReport setNonFatal() { nonFatal = true; return this; @@ -38,6 +42,9 @@ public class CrashReport { if (!stackTrace.contains("org.jackhuang")) return false; + if (throwable instanceof VirtualMachineError) + return false; + return true; } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/CrashWindow.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/CrashWindow.java index 46ce19abc..0d08bb5be 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/CrashWindow.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/CrashWindow.java @@ -27,6 +27,7 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.stage.Stage; import org.jackhuang.hmcl.Metadata; +import org.jackhuang.hmcl.countly.CrashReport; import org.jackhuang.hmcl.upgrade.UpdateChecker; import static org.jackhuang.hmcl.ui.FXUtils.newImage; @@ -37,16 +38,18 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n; */ public class CrashWindow extends Stage { - public CrashWindow(String text) { + public CrashWindow(CrashReport report) { Label lblCrash = new Label(); - if (UpdateChecker.isOutdated()) - lblCrash.setText(i18n("launcher.crash_out_dated")); + if (report.getThrowable() instanceof InternalError) + lblCrash.setText(i18n("launcher.crash.java_internal_error")); + else if (UpdateChecker.isOutdated()) + lblCrash.setText(i18n("launcher.crash.hmcl_out_dated")); else lblCrash.setText(i18n("launcher.crash")); lblCrash.setWrapText(true); TextArea textArea = new TextArea(); - textArea.setText(text); + textArea.setText(report.getDisplayText()); textArea.setEditable(false); Button btnContact = new Button(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/util/CrashReporter.java b/HMCL/src/main/java/org/jackhuang/hmcl/util/CrashReporter.java index 5ec3d2e31..bb097beca 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/util/CrashReporter.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/util/CrashReporter.java @@ -97,13 +97,11 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler { if (!report.shouldBeReport()) return; - String text = report.getDisplayText(); - - LOG.log(Level.SEVERE, text); + LOG.log(Level.SEVERE, report.getDisplayText()); Platform.runLater(() -> { if (checkThrowable(e)) { if (showCrashWindow) { - new CrashWindow(text).show(); + new CrashWindow(report).show(); } if (!UpdateChecker.isOutdated() && IntegrityChecker.isSelfVerified()) { reportToServer(report); diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index ad12af641..c3f1104c0 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -710,7 +710,8 @@ launcher.cache_directory.disabled=Disabled launcher.cache_directory.invalid=Unable to create cache directory, falling back to default. launcher.contact=Contact Us launcher.crash=Hello Minecraft! Launcher has encountered a fatal error\! Please copy the following log and ask for help on our Discord community, GitHub or Minecraft Forum. -launcher.crash_out_dated=Hello Minecraft! Launcher has encountered a fatal error\! Your launcher is outdated. Please update your launcher\! +launcher.crash.java_internal_error=Hello Minecraft! Launcher has encountered a fatal error because your Java is broken. Please uninstall your Java, and download a suitable Java here. +launcher.crash.hmcl_out_dated=Hello Minecraft! Launcher has encountered a fatal error\! Your launcher is outdated. Please update your launcher\! launcher.update_java=Please update your Java version. login.empty_username=You have not set your username yet\! diff --git a/HMCL/src/main/resources/assets/lang/I18N_es.properties b/HMCL/src/main/resources/assets/lang/I18N_es.properties index 3257f51d1..2b43c521b 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_es.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_es.properties @@ -659,7 +659,7 @@ launcher.cache_directory.disabled=Desactivado launcher.cache_directory.invalid=No se ha podido crear el directorio de la caché, volviendo a los valores por defecto. launcher.contact=Contacta con nosotros launcher.crash=¡Hello Minecraft! Launcher ha encontrado un error fatal. Por favor, copie el siguiente registro y pida ayuda en nuestra comunidad en Discord, GitHub o Minecraft Forums. -launcher.crash_out_dated=¡Hello Minecraft! Launcher ha encontrado un error fatal. Su launcher está desactualizado. Por favor, ¡actualícelo!. +launcher.crash.hmcl_out_dated=¡Hello Minecraft! Launcher ha encontrado un error fatal. Su launcher está desactualizado. Por favor, ¡actualícelo!. launcher.update_java=Por favor, actualice su versión de Java. login.empty_username=¡Todavía no has puesto tu nombre de usuario! diff --git a/HMCL/src/main/resources/assets/lang/I18N_ja.properties b/HMCL/src/main/resources/assets/lang/I18N_ja.properties index 8c7083585..1b2c165bc 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_ja.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_ja.properties @@ -505,7 +505,7 @@ launcher.cache_directory.disabled=無効(常にゲームパスを使用する) launcher.cache_directory.invalid=無効なディレクトリ。デフォルト設定の復元。 launcher.contact=お問い合わせ launcher.crash=Hello Minecraft!ランチャーがクラッシュしました!次のコンテンツをコピーして、MCBBS、Baidu Tieba、GitHub、またはMinecraftForumを介してフィードバックを送信してください。 -launcher.crash_out_dated=Hello Minecraft!ランチャーがクラッシュしました!ランチャーが古くなっています。ランチャーを更新してください! +launcher.crash.hmcl_out_dated=Hello Minecraft!ランチャーがクラッシュしました!ランチャーが古くなっています。ランチャーを更新してください! launcher.update_java=Javaを更新してください。 login.empty_username=ユーザー名を設定していません! diff --git a/HMCL/src/main/resources/assets/lang/I18N_ru.properties b/HMCL/src/main/resources/assets/lang/I18N_ru.properties index 0400c3c7b..f94189085 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_ru.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_ru.properties @@ -510,7 +510,7 @@ launcher.cache_directory.disabled=Отключено launcher.cache_directory.invalid=Недопустимый каталог. Восстановление настроек по умолчанию. launcher.contact=Свяжитесь с нами launcher.crash=Лаунчер Hello Minecraft! рухнул! Скопируйте следующее содержимое и отправьте отзыв через MCBBS, Baidu Tieba, GitHub или Minecraft Forum. -launcher.crash_out_dated=Лаунчер Hello Minecraft! рухнул! Ваш лаунчер устарел, обновите его! +launcher.crash.hmcl_out_dated=Лаунчер Hello Minecraft! рухнул! Ваш лаунчер устарел, обновите его! launcher.update_java=Обновите свой Java. login.empty_username=Вы не задали имя пользователя! diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh.properties b/HMCL/src/main/resources/assets/lang/I18N_zh.properties index fc92c65d0..67fe253fe 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh.properties @@ -582,7 +582,8 @@ launcher.cache_directory.disabled=停用 launcher.cache_directory.invalid=無法建立自訂的快取目錄,還原至預設設定 launcher.contact=聯絡我們 launcher.crash=Hello Minecraft! Launcher 遇到了無法處理的錯誤,請複製下列內容並透過 MCBBS、貼吧、GitHub 或 Minecraft Forum 回報 bug。 -launcher.crash_out_dated=Hello Minecraft! Launcher 遇到了無法處理的錯誤,已偵測到您的啟動器不是最新版本,請更新後重試! +launcher.crash.java_internal_error=HHello Minecraft! Launcher 由於當前 Java 損壞而無法繼續運行,請卸載當前 Java,點擊 此處 安裝合適的 Java 版本。 +launcher.crash.hmcl_out_dated=Hello Minecraft! Launcher 遇到了無法處理的錯誤,已偵測到您的啟動器不是最新版本,請更新後重試! launcher.update_java=請更新您的 Java login.empty_username=你還未設定使用者名稱! diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index 94d790859..32617d018 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -581,7 +581,8 @@ launcher.cache_directory.disabled=禁用(总是使用游戏路径) launcher.cache_directory.invalid=无法创建自定义的缓存目录,恢复默认设置 launcher.contact=联系我们 launcher.crash=Hello Minecraft! Launcher 遇到了无法处理的错误,请复制下列内容并点击右下角的按钮反馈 bug。 -launcher.crash_out_dated=Hello Minecraft! Launcher 遇到了无法处理的错误,已检测到您的启动器不是最新版本,请更新后再试。 +launcher.crash.java_internal_error=Hello Minecraft! Launcher 由于当前 Java 损坏而无法继续运行,请卸载当前 Java,点击 此处 安装合适的 Java 版本。 +launcher.crash.hmcl_out_dated=Hello Minecraft! Launcher 遇到了无法处理的错误,已检测到您的启动器不是最新版本,请更新后再试。 launcher.update_java=请更新您的 Java \n你可以访问\n https://docs.hmcl.net/help.html \n页面寻求帮助。 login.empty_username=你还未设置用户名!