Skip to content

Commit

Permalink
Fix/load extension log load failure (#641)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
schroda authored Aug 6, 2023
1 parent 6fd291c commit 00bc055
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>()

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 00bc055

Please sign in to comment.