diff --git a/scalabot-app/src/main/kotlin/AppConfigs.kt b/scalabot-app/src/main/kotlin/AppConfigs.kt index b279068..f67e43a 100644 --- a/scalabot-app/src/main/kotlin/AppConfigs.kt +++ b/scalabot-app/src/main/kotlin/AppConfigs.kt @@ -331,13 +331,23 @@ private object GsonConst { } internal fun loadAppConfig(configFile: File = AppPaths.DEFAULT_CONFIG_APPLICATION.file): AppConfig { - configFile.bufferedReader(StandardCharsets.UTF_8).use { - return GsonConst.appConfigGson.fromJson(it, AppConfig::class.java)!! + try { + configFile.bufferedReader(StandardCharsets.UTF_8).use { + return GsonConst.appConfigGson.fromJson(it, AppConfig::class.java)!! + } + } catch (e: Exception) { + log.error { "读取 config.json 时发生错误, 请检查配置格式是否正确." } + throw e } } -internal fun loadBotConfig(botConfigFile: File = AppPaths.DEFAULT_CONFIG_BOT.file): Set { - botConfigFile.bufferedReader(StandardCharsets.UTF_8).use { - return GsonConst.botConfigGson.fromJson(it, object : TypeToken>() {}.type)!! +internal fun loadBotConfig(botConfigFile: File = AppPaths.DEFAULT_CONFIG_BOT.file): Set? { + try { + botConfigFile.bufferedReader(StandardCharsets.UTF_8).use { + return GsonConst.botConfigGson.fromJson(it, object : TypeToken>() {}.type)!! + } + } catch (e: Exception) { + log.error(e) { "读取 Bot 配置文件 (bot.json) 时发生错误, 请检查配置格式是否正确." } + return null } } diff --git a/scalabot-app/src/main/kotlin/AppMain.kt b/scalabot-app/src/main/kotlin/AppMain.kt index 6663765..cb2027a 100644 --- a/scalabot-app/src/main/kotlin/AppMain.kt +++ b/scalabot-app/src/main/kotlin/AppMain.kt @@ -108,7 +108,7 @@ internal class Launcher(private val config: AppConfig = Const.config) : AutoClos @Synchronized fun launch(): Boolean { - val botConfigs = loadBotConfig() + val botConfigs = loadBotConfig() ?: return false if (botConfigs.isEmpty()) { log.warn { "尚未配置任何机器人, 请先配置机器人后再启动本程序." } return false