From 3168f2d4bb9e3d20246649b38e70b4d2ccad24d2 Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Fri, 23 May 2025 21:24:41 +0800 Subject: [PATCH] =?UTF-8?q?6.6.3=20-=20Alpha5=20-=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=BC=82=E5=B8=B8=E6=B6=88=E6=81=AF=E5=9C=A8?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=8F=B0=E7=9A=84=E6=98=BE=E7=A4=BA=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E4=B8=8E=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changelog/lang_zh-Hans.json | 1 + .../autojs/runtime/api/augment/Augmentable.kt | 33 +++----- .../WrappedIllegalArgumentException.kt | 75 ++++++++++++------- app/src/main/res/values-ar/strings.xml | 1 - app/src/main/res/values-en/strings.xml | 1 - app/src/main/res/values-es/strings.xml | 1 - app/src/main/res/values-fr/strings.xml | 1 - app/src/main/res/values-ja/strings.xml | 1 - app/src/main/res/values-ko/strings.xml | 1 - app/src/main/res/values-ru/strings.xml | 1 - app/src/main/res/values-zh-rHK/strings.xml | 1 - app/src/main/res/values-zh-rTW/strings.xml | 1 - app/src/main/res/values-zh/strings.xml | 1 - app/src/main/res/values/strings.xml | 1 - 14 files changed, 61 insertions(+), 59 deletions(-) diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json index b8bc541e..3295c5d6 100644 --- a/.changelog/lang_zh-Hans.json +++ b/.changelog/lang_zh-Hans.json @@ -45,6 +45,7 @@ "已忽略更新记录及客户端模式连接地址记录支持清空操作", "版本更新信息支持多语言显示 (与当前显示语言同步)", "使用异步加载方式一定程度提升文件管理器列表滑动流畅性", + "脚本异常消息在控制台的显示内容与格式", "APK 文件签名信息提升检测效率", "APK 文件类型信息及媒体文件类型信息优化对话框显示效率及信息展示逻辑", "Gradle 构建脚本提升版本自适应能力 _[`discussion #369`](http://discussions.autojs6.com/369)_" diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/Augmentable.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/Augmentable.kt index 14dec266..5dc3f086 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/Augmentable.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/Augmentable.kt @@ -14,6 +14,7 @@ import org.autojs.autojs.runtime.api.augment.events.Events import org.autojs.autojs.runtime.exception.ScriptException import org.autojs.autojs.runtime.exception.ScriptInterruptedException import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException +import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException.Companion.getRefinedStackTrace import org.autojs.autojs.runtime.exception.WrappedRuntimeException import org.autojs.autojs.util.RhinoUtils import org.autojs.autojs.util.RhinoUtils.DEFAULT_CALLER @@ -437,38 +438,28 @@ abstract class Augmentable(private val scriptRuntime: ScriptRuntime? = null) : F else -> targetEx } else -> t - } + }.also { it.printStackTrace() } + if (ScriptInterruptedException.causedByInterrupt(e)) { throw e } val funcNameSuffix = if (funcName != funcNameAlias) " (${globalContext.getString(R.string.text_alias)}: $funcNameAlias)" else "" val methodDescription = "$key.$funcName$funcNameSuffix" - val message = globalContext.getString(R.string.error_failed_to_invoke_method_with_description, methodDescription) + val message = globalContext.getString(R.string.error_failed_to_call_method, methodDescription) val niceMessage = when (val errMsg = e.message) { - null -> message + null -> e.takeUnless { it is WrappedIllegalArgumentException }?.stackTraceToString()?.let { + getRefinedStackTrace(message, it) + } ?: message else -> { val refined = errMsg.replaceFirst(Regex("^(Wrapped )?\\w*(\\.\\w+)*(Exception|Error): "), "") val trailingDot = if (refined.endsWith(".")) "" else "." - "$message. $refined$trailingDot\n$e" + when (e is WrappedIllegalArgumentException) { + true -> "$message. $refined$trailingDot" + else -> "$message. $refined$trailingDot\n$e" + } } } - e.printStackTrace() - when (e) { - is WrappedIllegalArgumentException -> { - // @Hint by SuperMonster003 on Oct 31, 2024. - // ! Here we force WrappedIllegalArgumentException to be converted to RuntimeException - // ! to prevent Rhino JavaScript code's try..catch blocks from catching this important exception. - // ! Additionally, WrappedIllegalArgumentException itself inherits from WrappedException, - // ! so the exception's code line number will be included when printing the error stack trace. - // ! zh-CN: - // ! 这里强制将 WrappedIllegalArgumentException 转换为 RuntimeException, - // ! 是为了让 Rhino JavaScript 代码的 try..catch 块无法捕获这个重要异常. - // ! 另外 WrappedIllegalArgumentException 本身继承了 WrappedException, - // ! 因此在打印错误堆栈信息时会包含异常所在的 code line number (代码行号). - throw RuntimeException(niceMessage, e) - } - else -> throw WrappedRuntimeException(niceMessage, e) - } + throw WrappedRuntimeException(niceMessage) } }, NOT_CONSTRUCTABLE) destination.defineProperty(funcNameAlias, f, attributes) diff --git a/app/src/main/java/org/autojs/autojs/runtime/exception/WrappedIllegalArgumentException.kt b/app/src/main/java/org/autojs/autojs/runtime/exception/WrappedIllegalArgumentException.kt index e9df2c30..b3269eec 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/exception/WrappedIllegalArgumentException.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/exception/WrappedIllegalArgumentException.kt @@ -6,32 +6,7 @@ import org.mozilla.javascript.EvaluatorException // @Hint by SuperMonster003 on Oct 31, 2024. // ! This class include the exception's code line number when printing the error stack trace. // ! zh-CN: 当前类可在打印错误堆栈信息时包含异常所在的 code line number (代码行号). -class WrappedIllegalArgumentException(detailMessage: String) : EvaluatorException(run { - var droppedFormer = false - var droppedLatter = false - val result = mutableListOf() - for (e in Thread.currentThread().stackTrace) { - if ("$e".startsWith(WrappedIllegalArgumentException::class.java.name)) { - droppedFormer = true - result.clear() - continue - } - if ("$e".contains(Regex("^(java.lang.reflect.Method.invoke|org.mozilla.javascript.Interpreter)"))) { - droppedLatter = true - break - } - result += "$e" - } - if (droppedFormer) result.add(0, ELLIPSIS_MARK) - if (droppedLatter) result.add(ELLIPSIS_MARK) - buildString { - appendLine(detailMessage) - appendLine() - appendLine(if (droppedFormer || droppedLatter) "Stack trace (partial):" else "Stack trace:") - appendLine() - appendLine(result.joinToString("\n") { " $it" }) - } -}) { +class WrappedIllegalArgumentException(detailMessage: String) : EvaluatorException(getRefinedStackTrace(detailMessage)) { private val exception = IllegalArgumentException(details()) @@ -66,7 +41,53 @@ class WrappedIllegalArgumentException(detailMessage: String) : EvaluatorExceptio companion object { private const val ELLIPSIS_MARK = "... ..." + private const val LINE_INDENT = 4 + + @JvmStatic + @JvmOverloads + fun getRefinedStackTrace(detailMessage: String, stackTrackString: String? = null): String { + var withAtSymbol = false + var droppedFormer = false + var droppedLatter = false + val result = mutableListOf() + val stackTraces = stackTrackString?.split("\n") ?: Thread.currentThread().stackTrace.map { it.toString() } + for (e in stackTraces) { + if (e.startsWith(WrappedIllegalArgumentException::class.java.name)) { + droppedFormer = true + withAtSymbol = false + result.clear() + continue + } + if (e.contains(Regex("^(\\s*at\\s+)?\\s*(java.lang.reflect.Method.invoke|org.mozilla.javascript.Interpreter)"))) { + droppedLatter = true + break + } + if (e.contains(Regex("^\\s*at\\s+"))) { + withAtSymbol = true + } + result += e.trimStart() + } + if (droppedFormer) result.add(0, ELLIPSIS_MARK) + if (droppedLatter) result.add(ELLIPSIS_MARK) + + if (result.isEmpty()) return detailMessage + + return buildString { + appendLine(if (detailMessage.endsWith(".")) detailMessage else "$detailMessage.") + appendLine() + appendLine(if (droppedFormer || droppedLatter) "Stack trace (partial):" else "Stack trace:") + appendLine() + appendLine(result.joinToString("\n") { + when { + !withAtSymbol -> " ".repeat(LINE_INDENT) + it + it.contains(Regex("^\\s*at\\s+")) -> " ".repeat(LINE_INDENT) + it + it == ELLIPSIS_MARK -> " ".repeat(LINE_INDENT) + it + else -> it + } + }) + } + } } -} +} \ No newline at end of file diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index e62bda17..aefeb5d9 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -187,7 +187,6 @@ فشل منح Shizuku حق الوصول فشل إنشاء المثيل \"%s\" - فشل في استدعاء الطريقة %1$s فشل في عرض المحتوى فشل في استرداد معلومات الإصدار تعذّر جلب سجل الإصدارات diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index 00f617ef..ebfe355a 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -182,7 +182,6 @@ Failed to grant Shizuku access Failed to instantiate "%s" - Failed to invoke method %1$s Failed to render content Failed to retrieve release notes Failed to retrieve version histories diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 5e6b3cbd..16e107ba 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -185,7 +185,6 @@ Fallo en la concesión de permisos Shizuku Error al instanciar \"%s\" - Error al invocar el método %1$s Error al renderizar el contenido No se pudo obtener la información de la versión No se pudo obtener el historial de versiones diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index d5d22eeb..68ba01cd 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -185,7 +185,6 @@ Échec de l\'octroi de la permission de Shizuku Échec de l\'instanciation de \"%s\" - Échec de l\'appel de la méthode %1$s Impossible d\'afficher le contenu Échec de la récupération des informations de version Impossible de récupérer l\'historique des versions diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 40ada7f8..5b8e64d2 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -186,7 +186,6 @@ Shizuku の権限付与に失敗しました \"%s\" のインスタンス化に失敗しました - メソッド %1$s の呼び出しに失敗しました コンテンツの表示に失敗しました バージョン情報の取得に失敗しました バージョン履歴を取得できません diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index c0c36f7b..93155d74 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -187,7 +187,6 @@ Shizuku 권한을 부여하지 못했습니다 \"%s\" 인스턴스 생성에 실패했습니다 - 메소드 %1$s 호출에 실패했습니다 콘텐츠 렌더링에 실패했습니다 버전 정보를 가져오지 못했습니다 버전 기록을 가져올 수 없습니다 diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 254330e4..1e7da599 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -185,7 +185,6 @@ Не удалось предоставить права на использование Shizuku Ошибка создания экземпляра \"%s\" - Ошибка вызова метода %1$s Не удалось отобразить содержимое Не удалось получить информацию о версии Не удалось получить историю версий diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 39643f57..e0f97fdb 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -183,7 +183,6 @@ Shizuku 權限授予失敗 實例 \"%s\" 創建失敗 - 方法 %1$s 調用失敗 內容渲染失敗 獲取版本信息失敗 獲取版本歷史失敗 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index fc6d1499..69a08d8b 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -183,7 +183,6 @@ Shizuku 許可權授予失敗 例項 \"%s\" 建立失敗 - 方法 %1$s 呼叫失敗 內容渲染失敗 獲取版本資訊失敗 獲取版本歷史失敗 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 49e916a5..57921b3d 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -183,7 +183,6 @@ Shizuku 权限授予失败 实例 \"%s\" 创建失败 - 方法 %1$s 调用失败 内容渲染失败 获取版本信息失败 获取版本历史失败 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2301a1ea..9cb6e638 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -413,7 +413,6 @@ Failed to grant Shizuku access Failed to instantiate "%s" - Failed to invoke method %1$s Failed to render content Failed to retrieve release notes Failed to retrieve version histories