simple-robot / simpler-robot

Simple Robot,一个bot风格的Kotlin多平台事件调度框架,异步高效、Java友好!/ A Bot-style Kotlin Multiplatform event scheduling framework, asynchronous and high-performance, java-friendly! 🐱😼😻😸
https://simbot.forte.love
GNU Lesser General Public License v3.0
521 stars 43 forks source link

启动项目报错,疑似QQ组件库问题或其他 #929

Closed ParNal3355 closed 3 months ago

ParNal3355 commented 3 months ago

是否会提供贡献?

版本号

4.6.0

附加版本

使用IDEA创建Spring Boot项目,将依赖更新到最新版本(核心:4.6.0。QQ组件库:4.0.0。Ktor:2.3.12。)。 安装后立刻启动,无异常。使用@EnableSimbot注释启动类,启动后报错。 经测试,疑似QQ组件库问题。代码以及报错内容在下方写到。 测试组合: ----核心------QQ组件库--Ktor-----结果 4.0.0-dev18--4.0.0-dev8--2.3.8----正常 ---4.6.0------4.0.0-dev8--2.3.8----正常 ---4.6.0------4.0.0-dev8--2.3.12---正常 ---4.6.0---------4.0.0-----2.3.12---报错

涉及的编程语言

Java

项目构建工具

Maven

涉及的组件库

QQ机器人

问题描述

pom.xml内容:

......
        <!-- simbot4核心库 -->
        <dependency>
            <groupId>love.forte.simbot</groupId>
            <artifactId>simbot-core-spring-boot-starter</artifactId>
            <version>4.6.0</version>
        </dependency>
        <!-- QQ组件库 -->
        <dependency>
            <groupId>love.forte.simbot.component</groupId>
            <artifactId>simbot-component-qq-guild-core-jvm</artifactId>
            <version>4.0.0</version>
        </dependency>

        <!-- ktor引擎-CLO -->
        <dependency>
        <groupId>io.ktor</groupId>
        <artifactId>ktor-client-cio-jvm</artifactId>
        <version>2.3.12</version>
        <scope>runtime</scope>
        </dependency>

    </dependencies>
......

补全机器人配置文件,直接运行结果:

2024-08-27T22:13:19.895+08:00  INFO 21580 --- [bot-maven-QQ] [           main] o.e.botmavenqq.BotMavenQqApplication     : Starting BotMavenQqApplication using Java 21.0.2 with PID 21580 (E:\QqBot (省略)
2024-08-27T22:13:19.897+08:00  INFO 21580 --- [bot-maven-QQ] [           main] o.e.botmavenqq.BotMavenQqApplication     : No active profile set, falling back to 1 default profile: "default"
2024-08-27T22:13:20.471+08:00  INFO 21580 --- [bot-maven-QQ] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2024-08-27T22:13:20.480+08:00  INFO 21580 --- [bot-maven-QQ] [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-08-27T22:13:20.481+08:00  INFO 21580 --- [bot-maven-QQ] [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.28]
2024-08-27T22:13:20.524+08:00  INFO 21580 --- [bot-maven-QQ] [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-08-27T22:13:20.525+08:00  INFO 21580 --- [bot-maven-QQ] [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 596 ms
2024-08-27T22:13:20.755+08:00  INFO 21580 --- [bot-maven-QQ] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path '/'
2024-08-27T22:13:20.761+08:00  INFO 21580 --- [bot-maven-QQ] [           main] o.e.botmavenqq.BotMavenQqApplication     : Started BotMavenQqApplication in 1.12 seconds (process running for 1.616)

在启动类前加入@EnableSimbot注释:

import love.forte.simbot.spring.EnableSimbot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@EnableSimbot
@SpringBootApplication
public class BotMavenQqApplication {

    public static void main(String[] args) {
        SpringApplication.run(BotMavenQqApplication.class, args);
    }

}

启动项目,运行报错: 为方便阅读,我将报错内容分割以方便滑动。

:: Spring Boot ::                (v3.3.3)

2024-08-27T22:17:39.667+08:00  INFO 4456 --- [bot-maven-QQ] [           main] o.e.botmavenqq.BotMavenQqApplication     : Starting BotMavenQqApplication using Java 21.0.2 with PID 4456 (E:\QqBot  (省略)
2024-08-27T22:17:39.669+08:00  INFO 4456 --- [bot-maven-QQ] [           main] o.e.botmavenqq.BotMavenQqApplication     : No active profile set, falling back to 1 default profile: "default"
2024-08-27T22:17:40.601+08:00  INFO 4456 --- [bot-maven-QQ] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2024-08-27T22:17:40.612+08:00  INFO 4456 --- [bot-maven-QQ] [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-08-27T22:17:40.612+08:00  INFO 4456 --- [bot-maven-QQ] [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.28]
2024-08-27T22:17:40.656+08:00  INFO 4456 --- [bot-maven-QQ] [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-08-27T22:17:40.656+08:00  INFO 4456 --- [bot-maven-QQ] [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 944 ms
2024-08-27T22:17:40.725+08:00  INFO 4456 --- [bot-maven-QQ] [           main] love.forte.simbot.utils.BlockingRunner   : Blocking runner wait timeout is enabled with wait timeout 1m. You can enable debug logging for 'love.forte.simbot.utils.BlockingRunner' for more stack information or disable it with the JVM parameter '-Dsimbot.blockingRunner.disableWaitTimeout=true'.
2024-08-27T22:17:40.938+08:00  INFO 4456 --- [bot-maven-QQ] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path '/'
2024-08-27T22:17:40.943+08:00  INFO 4456 --- [bot-maven-QQ] [           main] o.e.botmavenqq.BotMavenQqApplication     : Started BotMavenQqApplication in 1.535 seconds (process running for 1.991)
2024-08-27T22:17:41.050+08:00  INFO 4456 --- [bot-maven-QQ] [           main] l.f.s.c.q.i.bot.QQGuildBotManagerImpl    : Registered bot appId: ********(省略)
2024-08-27T22:17:41.054+08:00  INFO 4456 --- [bot-maven-QQ] [           main] l.f.s.s.c.application.BotAutoLoader      : The number of registered bots is 1
2024-08-27T22:17:41.055+08:00  INFO 4456 --- [bot-maven-QQ] [           main] l.f.s.s.c.a.SimbotApplicationRunner      : Launch application SpringApplication(isActive=true, isCompleted=false, eventDispatcher=SimpleEventDispatcher, components=Components(values=[QQGuildComponent(id=simbot.qqguild)]), plugins=Plugins(values=[love.forte.simbot.component.qguild.internal.bot.QQGuildBotManagerImpl@4b691611])) with mode: NONE
2024-08-27T22:17:41.486+08:00 ERROR 4456 --- [bot-maven-QQ] [tcher-worker-18] l.f.s.s.c.application.BotAutoLoader      : There are certain bots that have exceptions in asynchronous startups, application will be cancelled

love.forte.simbot.spring.common.BotAutoStartOnFailureException: love.forte.simbot.qguild.QQGuildResultSerializationException: Response(status=200) deserialization failed: Fields [access_token, expires_in] are required for type with serial name 'love.forte.simbot.qguild.api.app.AppAccessToken', but they were missing at path: $
    at love.forte.simbot.spring.configuration.application.BotAutoLoader$startBotsInAsync$1.invokeSuspend(DefaultSimbotApplicationProcessor.kt:411) ~[simbot-core-spring-boot-starter-4.6.0.jar:na]
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[kotlin-stdlib-1.9.25.jar:1.9.25-release-852]
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:102) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
Caused by: love.forte.simbot.qguild.QQGuildResultSerializationException: Response(status=200) deserialization failed: Fields [access_token, expires_in] are required for type with serial name 'love.forte.simbot.qguild.api.app.AppAccessToken', but they were missing at path: $
    at love.forte.simbot.qguild.api.ApiRequests__ApiRequestsKt.requestData(ApiRequests.kt:214) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at love.forte.simbot.qguild.api.ApiRequests.requestData(Unknown Source) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at love.forte.simbot.qguild.api.ApiRequests__ApiRequestsKt$requestData$1.invokeSuspend(ApiRequests.kt) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[kotlin-stdlib-1.9.25.jar:1.9.25-release-852]
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
    ... 4 common frames omitted
Caused by: kotlinx.serialization.MissingFieldException: Fields [access_token, expires_in] are required for type with serial name 'love.forte.simbot.qguild.api.app.AppAccessToken', but they were missing at path: $
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:95) ~[kotlinx-serialization-json-jvm-1.6.3.jar:na]
    at kotlinx.serialization.json.Json.decodeFromString(Json.kt:107) ~[kotlinx-serialization-json-jvm-1.6.3.jar:na]
    at love.forte.simbot.qguild.api.ApiRequests__ApiRequestsKt.decodeResponse(ApiRequests.kt:238) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at love.forte.simbot.qguild.api.ApiRequests.decodeResponse(Unknown Source) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at love.forte.simbot.qguild.api.ApiRequests__ApiRequestsKt.requestData(ApiRequests.kt:210) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    ... 8 common frames omitted
Caused by: kotlinx.serialization.MissingFieldException: Fields [access_token, expires_in] are required for type with serial name 'love.forte.simbot.qguild.api.app.AppAccessToken', but they were missing
    at kotlinx.serialization.internal.PluginExceptionsKt.throwMissingFieldException(PluginExceptions.kt:20) ~[kotlinx-serialization-core-jvm-1.6.3.jar:1.6.3]
    at love.forte.simbot.qguild.api.app.AppAccessToken.<init>(GetAppAccessTokenApi.kt:84) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at love.forte.simbot.qguild.api.app.AppAccessToken$$serializer.deserialize(GetAppAccessTokenApi.kt:84) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at love.forte.simbot.qguild.api.app.AppAccessToken$$serializer.deserialize(GetAppAccessTokenApi.kt:84) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69) ~[kotlinx-serialization-json-jvm-1.6.3.jar:na]
    ... 12 common frames omitted
2024-08-27T22:17:41.489+08:00  INFO 4456 --- [bot-maven-QQ] [tcher-worker-18] l.f.s.s.c.a.SimbotApplicationRunner      : Application SpringApplication(isActive=false, isCompleted=true, eventDispatcher=SimpleEventDispatcher, components=Components(values=[QQGuildComponent(id=simbot.qqguild)]), plugins=Plugins(values=[love.forte.simbot.component.qguild.internal.bot.QQGuildBotManagerImpl@4b691611])) was cancelled with cause: love.forte.simbot.qguild.QQGuildResultSerializationException: Response(status=200) deserialization failed: Fields [access_token, expires_in] are required for type with serial name 'love.forte.simbot.qguild.api.app.AppAccessToken', but they were missing at path: $

java.util.concurrent.CancellationException: love.forte.simbot.qguild.QQGuildResultSerializationException: Response(status=200) deserialization failed: Fields [access_token, expires_in] are required for type with serial name 'love.forte.simbot.qguild.api.app.AppAccessToken', but they were missing at path: $
    at kotlinx.coroutines.ExceptionsKt.CancellationException(Exceptions.kt:17) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
    at love.forte.simbot.spring.application.internal.SpringApplicationImpl.cancel(SpringApplicationImpl.kt:89) ~[simbot-core-spring-boot-starter-4.6.0.jar:na]
    at love.forte.simbot.spring.configuration.application.BotAutoLoader$startBotsInAsync$1.invokeSuspend(DefaultSimbotApplicationProcessor.kt:417) ~[simbot-core-spring-boot-starter-4.6.0.jar:na]
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[kotlin-stdlib-1.9.25.jar:1.9.25-release-852]
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:102) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
Caused by: love.forte.simbot.spring.common.BotAutoStartOnFailureException: love.forte.simbot.qguild.QQGuildResultSerializationException: Response(status=200) deserialization failed: Fields [access_token, expires_in] are required for type with serial name 'love.forte.simbot.qguild.api.app.AppAccessToken', but they were missing at path: $
    at love.forte.simbot.spring.configuration.application.BotAutoLoader$startBotsInAsync$1.invokeSuspend(DefaultSimbotApplicationProcessor.kt:411) ~[simbot-core-spring-boot-starter-4.6.0.jar:na]
    ... 6 common frames omitted
Caused by: love.forte.simbot.qguild.QQGuildResultSerializationException: Response(status=200) deserialization failed: Fields [access_token, expires_in] are required for type with serial name 'love.forte.simbot.qguild.api.app.AppAccessToken', but they were missing at path: $
    at love.forte.simbot.qguild.api.ApiRequests__ApiRequestsKt.requestData(ApiRequests.kt:214) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at love.forte.simbot.qguild.api.ApiRequests.requestData(Unknown Source) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at love.forte.simbot.qguild.api.ApiRequests__ApiRequestsKt$requestData$1.invokeSuspend(ApiRequests.kt) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[kotlin-stdlib-1.9.25.jar:1.9.25-release-852]
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) ~[kotlinx-coroutines-core-jvm-1.8.1.jar:na]
    ... 4 common frames omitted
Caused by: kotlinx.serialization.MissingFieldException: Fields [access_token, expires_in] are required for type with serial name 'love.forte.simbot.qguild.api.app.AppAccessToken', but they were missing at path: $
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:95) ~[kotlinx-serialization-json-jvm-1.6.3.jar:na]
    at kotlinx.serialization.json.Json.decodeFromString(Json.kt:107) ~[kotlinx-serialization-json-jvm-1.6.3.jar:na]
    at love.forte.simbot.qguild.api.ApiRequests__ApiRequestsKt.decodeResponse(ApiRequests.kt:238) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at love.forte.simbot.qguild.api.ApiRequests.decodeResponse(Unknown Source) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at love.forte.simbot.qguild.api.ApiRequests__ApiRequestsKt.requestData(ApiRequests.kt:210) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    ... 8 common frames omitted
Caused by: kotlinx.serialization.MissingFieldException: Fields [access_token, expires_in] are required for type with serial name 'love.forte.simbot.qguild.api.app.AppAccessToken', but they were missing
    at kotlinx.serialization.internal.PluginExceptionsKt.throwMissingFieldException(PluginExceptions.kt:20) ~[kotlinx-serialization-core-jvm-1.6.3.jar:1.6.3]
    at love.forte.simbot.qguild.api.app.AppAccessToken.<init>(GetAppAccessTokenApi.kt:84) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at love.forte.simbot.qguild.api.app.AppAccessToken$$serializer.deserialize(GetAppAccessTokenApi.kt:84) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at love.forte.simbot.qguild.api.app.AppAccessToken$$serializer.deserialize(GetAppAccessTokenApi.kt:84) ~[simbot-component-qq-guild-api-jvm-4.0.0.jar:na]
    at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69) ~[kotlinx-serialization-json-jvm-1.6.3.jar:na]
    ... 12 common frames omitted

复现方式

相关日志

No response

其他补充

我有以前旧版本框架下的机器人,运行正常,在备份后更新版本,结果仍然报错。 我将报错内容询问过AI,不知以下内容是否有帮助:

据您提供的错误日志,问题出在 love.forte.simbot.qguild.QQGuildResultSerializationException,这表明在反序列化 QQ 公会 API 的响应时失败了。具体来说,Fields [access_token, expires_in] are required for type with serial name 'love.forte.simbot.qguild.api.app.AppAccessToken', but they were missing at path: $ 指出了在尝试将响应解析为 AppAccessToken 类型时,必要的字段 access_token 和 expires_in 缺失了 。

这个问题可能是由于 API 响应的格式与预期不匹配导致的。解决这个问题,您可能需要:

1.检查 API 的响应确保所有必要的字段都存在。 2.确认您的 AppAccessToken 类型是否正确地映射了这些字段。 3.如果 API 响应格式有更新,您可能需要更新您的代码以匹配新的格式。 另外,从日志中可以看到应用程序因为异常而被取消启动,这通常是因为在 Spring Boot 应用程序中,@Async 异步任务抛出了未捕获的异常。Spring Boot 默认的 SimpleAsyncTaskExecutor 线程池会捕获并记录异常,但不会传播异常,导致应用程序启动流程中无法感知到这些异常。您可以通过自定义线程池并设置 setRejectedExecutionHandler 来处理这种异常传播问题 。

最后,您可能需要查看 kotlinx.serialization 文档来确保您的序列化和反序列化逻辑正确无误 。 如果您需要进一步的帮助来解决这个问题,您可以查看相关的社区讨论或文档

ForteScarlet commented 3 months ago

看一下你的配置文件(记得隐藏敏感信息),在 https://github.com/simple-robot/simbot-component-qq-guild/pull/163 中(大概从QQ组件的 v4.0.0-beta6 开始)迁移到了官方文档内推荐的新的鉴权方式,这种方式要求配置 appId 和 secret 而不再要求 token

ForteScarlet commented 3 months ago

以及可以开启 love.forte.simbot.qguild.api 的 debug 日志,查看出现异常之前最后所请求的API的相关日志

ParNal3355 commented 3 months ago

看一下你的配置文件(记得隐藏敏感信息),在 simple-robot/simbot-component-qq-guild#163 中(大概从QQ组件的 v4.0.0-beta6 开始)迁移到了官方文档内推荐的新的鉴权方式,这种方式要求配置 appId 和 secret 而不再要求token

{
  "component": "simbot.qqguild",
  "ticket": {
    "appId": "********",
    "secret": "",
    "token": "****************"
  },
  "config": {
    "serverUrl": "SANDBOX",
    "intents": {
      "type": "raw",
      "intents": 1073741827
    }
  }
}
ForteScarlet commented 3 months ago

配置上 secret 后再做尝试

ParNal3355 commented 3 months ago

看一下你的配置文件(记得隐藏敏感信息),在 simple-robot/simbot-component-qq-guild#163 中(大概从QQ组件的 v4.0.0-beta6 开始)迁移到了官方文档内推荐的新的鉴权方式,这种方式要求配置 appId 和 secret 而不再要求token

!添加secret后没事了,非常感谢——