Fix usage of deprecated functions (#1192)

* Fix usage of deprecated functions

* lint

* Lint

* Another
This commit is contained in:
Mitchell Syer
2024-12-07 23:56:42 -05:00
committed by GitHub
parent 1d541a30ae
commit 2e3af25dd4
10 changed files with 37 additions and 36 deletions

View File

@@ -97,7 +97,7 @@ class ApolloSubscriptionProtocolHandler(
try { try {
objectMapper.readValue(payload) objectMapper.readValue(payload)
} catch (exception: Exception) { } catch (exception: Exception) {
logger.error("Error parsing the subscription message", exception) logger.error(exception) { "Error parsing the subscription message" }
null null
} }
@@ -106,13 +106,13 @@ class ApolloSubscriptionProtocolHandler(
context: WsContext, context: WsContext,
): Flow<SubscriptionOperationMessage> { ): Flow<SubscriptionOperationMessage> {
if (operationMessage.id == null) { if (operationMessage.id == null) {
logger.error("GraphQL subscription operation id is required") logger.error { "GraphQL subscription operation id is required" }
return flowOf(basicConnectionErrorMessage) return flowOf(basicConnectionErrorMessage)
} }
if (sessionState.doesOperationExist(operationMessage)) { if (sessionState.doesOperationExist(operationMessage)) {
sessionState.terminateSession(context, CloseStatus(4409, "Subscriber for ${operationMessage.id} already exists")) sessionState.terminateSession(context, CloseStatus(4409, "Subscriber for ${operationMessage.id} already exists"))
logger.info("Already subscribed to operation ${operationMessage.id} for session ${context.sessionId()}") logger.info { "Already subscribed to operation ${operationMessage.id} for session ${context.sessionId()}" }
return emptyFlow() return emptyFlow()
} }
@@ -120,7 +120,7 @@ class ApolloSubscriptionProtocolHandler(
val payload = operationMessage.payload val payload = operationMessage.payload
if (payload == null) { if (payload == null) {
logger.error("GraphQL subscription payload was null instead of a GraphQLRequest object") logger.error { "GraphQL subscription payload was null instead of a GraphQLRequest object" }
return flowOf(SubscriptionOperationMessage(type = GQL_ERROR.type, id = operationMessage.id)) return flowOf(SubscriptionOperationMessage(type = GQL_ERROR.type, id = operationMessage.id))
} }
@@ -137,7 +137,7 @@ class ApolloSubscriptionProtocolHandler(
}.onCompletion { if (it == null) emitAll(onComplete(operationMessage)) } }.onCompletion { if (it == null) emitAll(onComplete(operationMessage)) }
.onStart { sessionState.saveOperation(context, operationMessage, currentCoroutineContext().job) } .onStart { sessionState.saveOperation(context, operationMessage, currentCoroutineContext().job) }
} catch (exception: Exception) { } catch (exception: Exception) {
logger.error("Error running graphql subscription", exception) logger.error(exception) { "Error running graphql subscription" }
// Do not terminate the session, just stop the operation messages // Do not terminate the session, just stop the operation messages
sessionState.completeOperation(operationMessage) sessionState.completeOperation(operationMessage)
return flowOf(SubscriptionOperationMessage(type = GQL_ERROR.type, id = operationMessage.id)) return flowOf(SubscriptionOperationMessage(type = GQL_ERROR.type, id = operationMessage.id))
@@ -168,19 +168,19 @@ class ApolloSubscriptionProtocolHandler(
private fun onPing(): Flow<SubscriptionOperationMessage> = flowOf(pongMessage) private fun onPing(): Flow<SubscriptionOperationMessage> = flowOf(pongMessage)
private fun onDisconnect(context: WsContext): Flow<SubscriptionOperationMessage> { private fun onDisconnect(context: WsContext): Flow<SubscriptionOperationMessage> {
logger.debug("Session \"${context.sessionId()}\" disconnected") logger.debug { "Session \"${context.sessionId()}\" disconnected" }
sessionState.terminateSession(context, CloseStatus(1000, "Normal Closure")) sessionState.terminateSession(context, CloseStatus(1000, "Normal Closure"))
return emptyFlow() return emptyFlow()
} }
private fun onUnknownOperation(operationMessage: SubscriptionOperationMessage): Flow<SubscriptionOperationMessage> { private fun onUnknownOperation(operationMessage: SubscriptionOperationMessage): Flow<SubscriptionOperationMessage> {
logger.error("Unknown subscription operation $operationMessage") logger.error { "Unknown subscription operation $operationMessage" }
sessionState.completeOperation(operationMessage) sessionState.completeOperation(operationMessage)
return emptyFlow() return emptyFlow()
} }
private fun onException(exception: Exception): Flow<SubscriptionOperationMessage> { private fun onException(exception: Exception): Flow<SubscriptionOperationMessage> {
logger.error("Error parsing the subscription message", exception) logger.error(exception) { "Error parsing the subscription message" }
return flowOf(basicConnectionErrorMessage) return flowOf(basicConnectionErrorMessage)
} }
} }

View File

@@ -66,7 +66,8 @@ object Page {
.selectAll() .selectAll()
.where { (PageTable.chapter eq chapterId) } .where { (PageTable.chapter eq chapterId) }
.orderBy(PageTable.index to SortOrder.ASC) .orderBy(PageTable.index to SortOrder.ASC)
.limit(1, index.toLong()) .limit(1)
.offset(index.toLong())
.first() .first()
} }
val tachiyomiPage = val tachiyomiPage =

View File

@@ -146,7 +146,7 @@ class Downloader(
} }
finishDownload(downloadLogger, download) finishDownload(downloadLogger, download)
} catch (e: CancellationException) { } catch (e: CancellationException) {
logger.debug("Downloader was stopped") logger.debug { "Downloader was stopped" }
availableSourceDownloads.filter { it.state == Downloading }.forEach { it.state = Queued } availableSourceDownloads.filter { it.state == Downloading }.forEach { it.state = Queued }
notifier(false, DownloadUpdate(STOPPED, download)) notifier(false, DownloadUpdate(STOPPED, download))
} catch (e: PauseDownloadException) { } catch (e: PauseDownloadException) {
@@ -154,7 +154,7 @@ class Downloader(
download.state = Queued download.state = Queued
notifier(false, DownloadUpdate(PAUSED, download)) notifier(false, DownloadUpdate(PAUSED, download))
} catch (e: Exception) { } catch (e: Exception) {
downloadLogger.warn("failed due to", e) downloadLogger.warn(e) { "failed due to" }
download.tries++ download.tries++
download.state = Error download.state = Error
notifier(false, DownloadUpdate(ERROR, download)) notifier(false, DownloadUpdate(ERROR, download))

View File

@@ -54,7 +54,7 @@ object Extension {
private val applicationDirs: ApplicationDirs by injectLazy() private val applicationDirs: ApplicationDirs by injectLazy()
suspend fun installExtension(pkgName: String): Int { suspend fun installExtension(pkgName: String): Int {
logger.debug("Installing $pkgName") logger.debug { "Installing $pkgName" }
val extensionRecord = extensionTableAsDataClass().first { it.pkgName == pkgName } val extensionRecord = extensionTableAsDataClass().first { it.pkgName == pkgName }
return installAPK { return installAPK {
@@ -144,7 +144,7 @@ object Extension {
val className = val className =
packageInfo.packageName + packageInfo.applicationInfo.metaData.getString(METADATA_SOURCE_CLASS) packageInfo.packageName + packageInfo.applicationInfo.metaData.getString(METADATA_SOURCE_CLASS)
logger.debug("Main class for extension is $className") logger.debug { "Main class for extension is $className" }
dex2jar(apkFilePath, jarFilePath, fileNameWithoutType) dex2jar(apkFilePath, jarFilePath, fileNameWithoutType)
extractAssetsFromApk(apkFilePath, jarFilePath) extractAssetsFromApk(apkFilePath, jarFilePath)
@@ -295,7 +295,7 @@ object Extension {
} }
fun uninstallExtension(pkgName: String) { fun uninstallExtension(pkgName: String) {
logger.debug("Uninstalling $pkgName") logger.debug { "Uninstalling $pkgName" }
val extensionRecord = transaction { ExtensionTable.selectAll().where { ExtensionTable.pkgName eq pkgName }.first() } val extensionRecord = transaction { ExtensionTable.selectAll().where { ExtensionTable.pkgName eq pkgName }.first() }
val fileNameWithoutType = extensionRecord[ExtensionTable.apkName].substringBefore(".apk") val fileNameWithoutType = extensionRecord[ExtensionTable.apkName].substringBefore(".apk")

View File

@@ -55,12 +55,12 @@ object ExtensionsList {
suspend fun fetchExtensionsCached() { suspend fun fetchExtensionsCached() {
// update if 60 seconds has passed or requested offline and database is empty // update if 60 seconds has passed or requested offline and database is empty
if (lastUpdateCheck + 60.seconds.inWholeMilliseconds < System.currentTimeMillis()) { if (lastUpdateCheck + 60.seconds.inWholeMilliseconds < System.currentTimeMillis()) {
logger.debug("Getting extensions list from the internet") logger.debug { "Getting extensions list from the internet" }
lastUpdateCheck = System.currentTimeMillis() lastUpdateCheck = System.currentTimeMillis()
fetchExtensions() fetchExtensions()
} else { } else {
logger.debug("used cached extension list") logger.debug { "used cached extension list" }
} }
} }

View File

@@ -69,7 +69,7 @@ object PackageTools {
.to(jarFilePath) .to(jarFilePath)
if (handler.hasException()) { if (handler.hasException()) {
val errorFile: Path = File(applicationDirs.extensionsRoot).toPath().resolve("$fileNameWithoutType-error.txt") val errorFile: Path = File(applicationDirs.extensionsRoot).toPath().resolve("$fileNameWithoutType-error.txt")
logger.error( logger.error {
""" """
Detail Error Information in File $errorFile Detail Error Information in File $errorFile
Please report this file to one of following link if possible (any one). Please report this file to one of following link if possible (any one).
@@ -77,8 +77,8 @@ object PackageTools {
https://bitbucket.org/pxb1988/dex2jar/issues https://bitbucket.org/pxb1988/dex2jar/issues
https://github.com/pxb1988/dex2jar/issues https://github.com/pxb1988/dex2jar/issues
dex2jar@googlegroups.com dex2jar@googlegroups.com
""".trimIndent(), """.trimIndent()
) }
handler.dump(errorFile, emptyArray<String>()) handler.dump(errorFile, emptyArray<String>())
} else { } else {
BytecodeEditor.fixAndroidClasses(jarFilePath) BytecodeEditor.fixAndroidClasses(jarFilePath)
@@ -97,7 +97,7 @@ object PackageTools {
dBuilder.parse(it) dBuilder.parse(it)
} }
logger.trace(parsed.manifestXml) logger.trace { parsed.manifestXml }
applicationInfo.metaData = applicationInfo.metaData =
Bundle().apply { Bundle().apply {

View File

@@ -137,21 +137,21 @@ object JavalinSetup {
) )
app.exception(NullPointerException::class.java) { e, ctx -> app.exception(NullPointerException::class.java) { e, ctx ->
logger.error("NullPointerException while handling the request", e) logger.error(e) { "NullPointerException while handling the request" }
ctx.status(404) ctx.status(404)
} }
app.exception(NoSuchElementException::class.java) { e, ctx -> app.exception(NoSuchElementException::class.java) { e, ctx ->
logger.error("NoSuchElementException while handling the request", e) logger.error(e) { "NoSuchElementException while handling the request" }
ctx.status(404) ctx.status(404)
} }
app.exception(IOException::class.java) { e, ctx -> app.exception(IOException::class.java) { e, ctx ->
logger.error("IOException while handling the request", e) logger.error(e) { "IOException while handling the request" }
ctx.status(500) ctx.status(500)
ctx.result(e.message ?: "Internal Server Error") ctx.result(e.message ?: "Internal Server Error")
} }
app.exception(IllegalArgumentException::class.java) { e, ctx -> app.exception(IllegalArgumentException::class.java) { e, ctx ->
logger.error("IllegalArgumentException while handling the request", e) logger.error(e) { "IllegalArgumentException while handling the request" }
ctx.status(400) ctx.status(400)
ctx.result(e.message ?: "Bad Request") ctx.result(e.message ?: "Bad Request")
} }

View File

@@ -137,7 +137,7 @@ fun applicationSetup() {
setupLogLevelUpdating(serverConfig.debugLogsEnabled, listOf(BASE_LOGGER_NAME)) setupLogLevelUpdating(serverConfig.debugLogsEnabled, listOf(BASE_LOGGER_NAME))
logger.info("Running Suwayomi-Server ${BuildConfig.VERSION} revision ${BuildConfig.REVISION}") logger.info { "Running Suwayomi-Server ${BuildConfig.VERSION} revision ${BuildConfig.REVISION}" }
logger.debug { logger.debug {
"Loaded config:\n" + "Loaded config:\n" +
@@ -202,7 +202,7 @@ fun applicationSetup() {
GlobalConfigManager.updateUserConfig() GlobalConfigManager.updateUserConfig()
} }
} catch (e: Exception) { } catch (e: Exception) {
logger.error("Exception while creating initial server.conf", e) logger.error(e) { "Exception while creating initial server.conf" }
} }
// copy local source icon // copy local source icon
@@ -216,7 +216,7 @@ fun applicationSetup() {
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
logger.error("Exception while copying Local source's icon", e) logger.error(e) { "Exception while copying Local source's icon" }
} }
// fixes #119 , ref: https://github.com/Suwayomi/Suwayomi-Server/issues/119#issuecomment-894681292 , source Id calculation depends on String.lowercase() // fixes #119 , ref: https://github.com/Suwayomi/Suwayomi-Server/issues/119#issuecomment-894681292 , source Id calculation depends on String.lowercase()
@@ -265,9 +265,9 @@ fun applicationSetup() {
) )
}.distinctUntilChanged(), }.distinctUntilChanged(),
{ (proxyEnabled, proxyVersion, proxyHost, proxyPort, proxyUsername, proxyPassword) -> { (proxyEnabled, proxyVersion, proxyHost, proxyPort, proxyUsername, proxyPassword) ->
logger.info( logger.info {
"Socks Proxy changed - enabled=$proxyEnabled address=$proxyHost:$proxyPort , username=$proxyUsername, password=[REDACTED]", "Socks Proxy changed - enabled=$proxyEnabled address=$proxyHost:$proxyPort , username=$proxyUsername, password=[REDACTED]"
) }
if (proxyEnabled) { if (proxyEnabled) {
System.setProperty("socksProxyHost", proxyHost) System.setProperty("socksProxyHost", proxyHost)
System.setProperty("socksProxyPort", proxyPort) System.setProperty("socksProxyPort", proxyPort)

View File

@@ -22,7 +22,7 @@ enum class ExitCode(
} }
fun shutdownApp(exitCode: ExitCode) { fun shutdownApp(exitCode: ExitCode) {
logger.info("Shutting Down Suwayomi-Server. Goodbye!") logger.info { "Shutting Down Suwayomi-Server. Goodbye!" }
exitProcess(exitCode.code) exitProcess(exitCode.code)
} }

View File

@@ -70,20 +70,20 @@ object AppMutex {
fun handleAppMutex() { fun handleAppMutex() {
when (checkAppMutex()) { when (checkAppMutex()) {
AppMutexState.Clear -> { AppMutexState.Clear -> {
logger.info("Mutex status is clear, Resuming startup.") logger.info { "Mutex status is clear, Resuming startup." }
} }
AppMutexState.TachideskInstanceRunning -> { AppMutexState.TachideskInstanceRunning -> {
logger.info("Another instance of Suwayomi-Server is running on $appIP:${serverConfig.port.value}") logger.info { "Another instance of Suwayomi-Server is running on $appIP:${serverConfig.port.value}" }
logger.info("Probably user thought Suwayomi-Server is closed so, opening webUI in browser again.") logger.info { "Probably user thought Suwayomi-Server is closed so, opening webUI in browser again." }
openInBrowser() openInBrowser()
logger.info("Aborting startup.") logger.info { "Aborting startup." }
shutdownApp(MutexCheckFailedTachideskRunning) shutdownApp(MutexCheckFailedTachideskRunning)
} }
AppMutexState.OtherApplicationRunning -> { AppMutexState.OtherApplicationRunning -> {
logger.error("A non Suwayomi-Server application is running on $appIP:${serverConfig.port.value}, aborting startup.") logger.error { "A non Suwayomi-Server application is running on $appIP:${serverConfig.port.value}, aborting startup." }
shutdownApp(MutexCheckFailedAnotherAppRunning) shutdownApp(MutexCheckFailedAnotherAppRunning)
} }
} }