From 297592b9f21c98d26375465e300f0e6a84c46dc0 Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 23 May 2022 23:16:05 +0100 Subject: [PATCH] Do not throw exception when failed to locate desensitization rules, for tests on CI --- .../kotlin/testFramework/desensitizer/Desensitizer.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mirai-core/src/commonTest/kotlin/testFramework/desensitizer/Desensitizer.kt b/mirai-core/src/commonTest/kotlin/testFramework/desensitizer/Desensitizer.kt index 70a84f536..6ac352d89 100644 --- a/mirai-core/src/commonTest/kotlin/testFramework/desensitizer/Desensitizer.kt +++ b/mirai-core/src/commonTest/kotlin/testFramework/desensitizer/Desensitizer.kt @@ -25,6 +25,7 @@ import net.mamoe.mirai.utils.* import net.mamoe.yamlkt.Yaml import net.mamoe.yamlkt.YamlBuilder import java.io.File +import java.net.URL import kotlin.reflect.KType import kotlin.reflect.full.createInstance import kotlin.reflect.full.findAnnotation @@ -58,13 +59,15 @@ internal class Desensitizer private constructor( val filename = systemProp("mirai.network.recording.desensitization.filepath", "local.desensitization.yml") - val file = + val file: URL? = File(filename).takeIf { it.isFile }?.toURI()?.toURL() ?: Thread.currentThread().contextClassLoader.getResource(filename) ?: Thread.currentThread().contextClassLoader.getResource("recording/configs/$filename") - ?: error("Could not find desensitization configuration!") - format.decodeFromString(file.readText()) + file?.readText()?.let { format.decodeFromString(it) } ?: kotlin.run { + logger.warning { "Couldn't find desensitization rules. You can set by system property 'mirai.network.recording.desensitization.filepath' to path to the desensitization configuration file, or use the 'local.desensitization.yml' by default." } + mapOf() + } }.also { logger.info { "Loaded ${it.size} desensitization rules." } }