From f4f7c7063ecb64fbd49640084c5c32e40821b348 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 5 Sep 2022 17:05:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/api/controller/BookController.kt | 2 +- .../java/io/legado/app/help/ContentProcessor.kt | 4 ++-- .../main/java/io/legado/app/help/CrashHandler.kt | 4 ++-- .../main/java/io/legado/app/help/JsExtensions.kt | 13 +++++-------- app/src/main/java/io/legado/app/model/Debug.kt | 16 ++++++++-------- .../main/java/io/legado/app/model/ReadBook.kt | 4 ++-- .../legado/app/model/analyzeRule/AnalyzeRule.kt | 2 +- .../app/ui/book/explore/ExploreShowViewModel.kt | 4 ++-- .../legado/app/ui/book/read/ReadBookViewModel.kt | 5 +++-- .../ui/book/read/config/BgTextConfigDialog.kt | 2 +- .../ui/book/source/manage/BookSourceViewModel.kt | 2 +- .../ui/rss/source/edit/RssSourceEditViewModel.kt | 4 ++-- .../ui/rss/source/manage/RssSourceViewModel.kt | 2 +- .../io/legado/app/utils/ContextExtensions.kt | 2 +- .../io/legado/app/utils/ThrowableExtensions.kt | 2 +- 15 files changed, 33 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/io/legado/app/api/controller/BookController.kt b/app/src/main/java/io/legado/app/api/controller/BookController.kt index d37a43aac..71636242e 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookController.kt @@ -188,7 +188,7 @@ object BookController { } returnData.setData(content) } catch (e: Exception) { - returnData.setErrorMsg(e.msg) + returnData.setErrorMsg(e.stackTraceStr) } return returnData } diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index 0fc46dd1a..a8db44beb 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -9,8 +9,8 @@ import io.legado.app.data.entities.ReplaceRule import io.legado.app.exception.RegexTimeoutException import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig -import io.legado.app.utils.msg import io.legado.app.utils.replace +import io.legado.app.utils.stackTraceStr import io.legado.app.utils.toastOnUi import kotlinx.coroutines.CancellationException import splitties.init.appCtx @@ -149,7 +149,7 @@ class ContentProcessor private constructor( } catch (e: RegexTimeoutException) { item.isEnabled = false appDb.replaceRuleDao.update(item) - return item.name + e.msg + return item.name + e.stackTraceStr } catch (e: CancellationException) { return mContent } catch (e: Exception) { diff --git a/app/src/main/java/io/legado/app/help/CrashHandler.kt b/app/src/main/java/io/legado/app/help/CrashHandler.kt index a13c38161..0de9105a7 100644 --- a/app/src/main/java/io/legado/app/help/CrashHandler.kt +++ b/app/src/main/java/io/legado/app/help/CrashHandler.kt @@ -8,7 +8,7 @@ import io.legado.app.model.ReadAloud import io.legado.app.utils.FileUtils import io.legado.app.utils.getFile import io.legado.app.utils.longToastOnUi -import io.legado.app.utils.msg +import io.legado.app.utils.stackTraceStr import splitties.init.appCtx import java.io.PrintWriter import java.io.StringWriter @@ -48,7 +48,7 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler { if (ex == null) return //保存日志文件 saveCrashInfo2File(ex) - context.longToastOnUi(ex.msg) + context.longToastOnUi(ex.stackTraceStr) Thread.sleep(3000) } diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index c9a1aae89..8280c8e6b 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -56,9 +56,8 @@ interface JsExtensions { analyzeUrl.getStrResponseAwait().body }.onFailure { AppLog.put("ajax(${urlStr}) error\n${it.localizedMessage}", it) - it.printOnDebug() }.getOrElse { - it.msg + it.stackTraceStr } } } @@ -91,10 +90,9 @@ interface JsExtensions { kotlin.runCatching { analyzeUrl.getStrResponseAwait() }.onFailure { - log("connect(${urlStr}) error\n${it.stackTraceToString()}") - it.printOnDebug() + AppLog.put("connect(${urlStr}) error\n${it.localizedMessage}", it) }.getOrElse { - StrResponse(analyzeUrl.url, it.localizedMessage) + StrResponse(analyzeUrl.url, it.stackTraceStr) } } } @@ -106,10 +104,9 @@ interface JsExtensions { kotlin.runCatching { analyzeUrl.getStrResponseAwait() }.onFailure { - log("ajax($urlStr,$header) error\n${it.stackTraceToString()}") - it.printOnDebug() + AppLog.put("ajax($urlStr,$header) error\n${it.localizedMessage}", it) }.getOrElse { - StrResponse(analyzeUrl.url, it.localizedMessage) + StrResponse(analyzeUrl.url, it.stackTraceStr) } } } diff --git a/app/src/main/java/io/legado/app/model/Debug.kt b/app/src/main/java/io/legado/app/model/Debug.kt index 8cab89c29..30b427788 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -9,7 +9,7 @@ import io.legado.app.model.rss.Rss import io.legado.app.model.webBook.WebBook import io.legado.app.utils.HtmlFormatter import io.legado.app.utils.isAbsUrl -import io.legado.app.utils.msg +import io.legado.app.utils.stackTraceStr import kotlinx.coroutines.CoroutineScope import java.text.SimpleDateFormat import java.util.* @@ -128,7 +128,7 @@ object Debug { } } .onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } } @@ -145,7 +145,7 @@ object Debug { log(debugSource, "︽内容页解析完成", state = 1000) } .onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } } @@ -204,7 +204,7 @@ object Debug { } } .onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } tasks.add(explore) } @@ -222,7 +222,7 @@ object Debug { } } .onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } tasks.add(search) } @@ -246,7 +246,7 @@ object Debug { } } .onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } tasks.add(info) } @@ -261,7 +261,7 @@ object Debug { contentDebug(scope, bookSource, book, it.first(), nextChapterUrl) } .onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } tasks.add(chapterList) } @@ -284,7 +284,7 @@ object Debug { ).onSuccess { log(debugSource, "︽正文页解析完成", state = 1000) }.onError { - log(debugSource, it.msg, state = -1) + log(debugSource, it.stackTraceStr, state = -1) } tasks.add(content) } diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index 7f9f6d1df..d1e4a1a43 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -14,7 +14,7 @@ import io.legado.app.model.webBook.WebBook import io.legado.app.service.BaseReadAloudService import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.provider.ChapterProvider -import io.legado.app.utils.msg +import io.legado.app.utils.stackTraceStr import io.legado.app.utils.toastOnUi import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO @@ -387,7 +387,7 @@ object ReadBook : CoroutineScope by MainScope() { } }.onError { AppLog.put("ChapterProvider ERROR", it) - appCtx.toastOnUi("ChapterProvider ERROR:\n${it.msg}") + appCtx.toastOnUi("ChapterProvider ERROR:\n${it.stackTraceStr}") }.onSuccess { success?.invoke() } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 1be49d990..a7588e903 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -667,7 +667,7 @@ class AnalyzeRule( log("ajax(${urlStr}) error\n${it.stackTraceToString()}") it.printOnDebug() }.getOrElse { - it.msg + it.stackTraceStr } } } diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt index 1ae0e2c61..067047f7c 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt @@ -9,8 +9,8 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.SearchBook import io.legado.app.model.webBook.WebBook -import io.legado.app.utils.msg import io.legado.app.utils.printOnDebug +import io.legado.app.utils.stackTraceStr import kotlinx.coroutines.Dispatchers.IO @@ -46,7 +46,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application page++ }.onError { it.printOnDebug() - errorLiveData.postValue(it.msg) + errorLiveData.postValue(it.stackTraceStr) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index d04486ac3..2aa416e4b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -254,11 +254,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { return@execute } } - throw NoStackTraceException("自动换源失败") + throw NoStackTraceException("没有搜索到 ${name}(${author})") }.onStart { ReadBook.upMsg(context.getString(R.string.source_auto_changing)) }.onError { - context.toastOnUi(it.msg) + AppLog.put("自动换源失败\n${it.localizedMessage}", it) + context.toastOnUi("自动换源失败\n${it.localizedMessage}") }.onFinally { ReadBook.upMsg(null) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 0f357bcc9..089070aee 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -322,7 +322,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) { importConfig(it) } }.onError { - longToast(it.msg) + longToast(it.stackTraceStr) } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index f90633923..ad3e2e426 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -128,7 +128,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) }.onSuccess { success.invoke(it) }.onError { - context.toastOnUi(it.msg) + context.toastOnUi(it.stackTraceStr) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index da911a5f4..184fe8d58 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -8,8 +8,8 @@ import io.legado.app.data.entities.RssSource import io.legado.app.help.RuleComplete import io.legado.app.help.http.CookieStore import io.legado.app.utils.getClipText -import io.legado.app.utils.msg import io.legado.app.utils.printOnDebug +import io.legado.app.utils.stackTraceStr import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers @@ -74,7 +74,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati finally.invoke(it) } }.onError { - context.toastOnUi(it.msg) + context.toastOnUi(it.stackTraceStr) } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 8bf64b790..52f0db6b5 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -83,7 +83,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) }.onSuccess { success.invoke(it) }.onError { - context.toastOnUi(it.msg) + context.toastOnUi(it.stackTraceStr) } } diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index 94e35680c..534cce626 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -325,7 +325,7 @@ fun Context.openFileUri(uri: Uri, type: String? = null) { try { startActivity(intent) } catch (e: Exception) { - toastOnUi(e.msg) + toastOnUi(e.stackTraceStr) } } diff --git a/app/src/main/java/io/legado/app/utils/ThrowableExtensions.kt b/app/src/main/java/io/legado/app/utils/ThrowableExtensions.kt index 088db9b3b..4163b8211 100644 --- a/app/src/main/java/io/legado/app/utils/ThrowableExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ThrowableExtensions.kt @@ -2,7 +2,7 @@ package io.legado.app.utils import java.io.IOException -val Throwable.msg: String +val Throwable.stackTraceStr: String get() { val stackTrace = stackTraceToString() val lMsg = this.localizedMessage ?: "noErrorMsg"