Fix/load extension log load failure (#641)

* Log extension load failure

In case the extension couldn't be loaded the error was never logged, making it impossible to analyse what was going on

* Log exception in "GetCatalogueSource:: getCatalogueSourceOrNull"

In case "GetCatalogueSource::getCatalogueSource" threw an error, this was never logged here
This commit is contained in:
schroda
2023-08-06 02:10:12 +02:00
committed by GitHub
parent 6fd291c7e3
commit 00bc055d69
2 changed files with 19 additions and 6 deletions
@@ -143,12 +143,17 @@ object PackageTools {
* It may return an instance of HttpSource or SourceFactory depending on the extension.
*/
fun loadExtensionSources(jarPath: String, className: String): Any {
logger.debug { "loading jar with path: $jarPath" }
val classLoader = jarLoaderMap[jarPath] ?: URLClassLoader(arrayOf<URL>(URL("file:$jarPath")))
val classToLoad = Class.forName(className, false, classLoader)
try {
logger.debug { "loading jar with path: $jarPath" }
val classLoader = jarLoaderMap[jarPath] ?: URLClassLoader(arrayOf<URL>(URL("file:$jarPath")))
val classToLoad = Class.forName(className, false, classLoader)
jarLoaderMap[jarPath] = classLoader
jarLoaderMap[jarPath] = classLoader
return classToLoad.getDeclaredConstructor().newInstance()
return classToLoad.getDeclaredConstructor().newInstance()
} catch (e: Exception) {
logger.error(e) { "Failed to load jar with path: $jarPath" }
throw e
}
}
}
@@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceFactory
import eu.kanade.tachiyomi.source.online.HttpSource
import mu.KotlinLogging
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
import org.kodein.di.DI
@@ -23,6 +24,8 @@ import suwayomi.tachidesk.server.ApplicationDirs
import java.util.concurrent.ConcurrentHashMap
object GetCatalogueSource {
private val logger = KotlinLogging.logger { }
private val sourceCache = ConcurrentHashMap<Long, CatalogueSource>()
private val applicationDirs by DI.global.instance<ApplicationDirs>()
@@ -57,7 +60,12 @@ object GetCatalogueSource {
}
fun getCatalogueSourceOrNull(sourceId: Long): CatalogueSource? {
return runCatching { getCatalogueSource(sourceId) }.getOrNull()
return try {
getCatalogueSource(sourceId)
} catch (e: Exception) {
logger.warn(e) { "getCatalogueSource($sourceId) failed" }
null
}
}
fun getCatalogueSourceOrStub(sourceId: Long): CatalogueSource {