fix(lark): contain panics in asynchronous card actions - #177
Open
kevinmatthe wants to merge 1 commit into
Open
Conversation
Reviewer's Guide添加一个对异步卡片操作任务进行 panic 保护的封装,以及一个回归测试,用于确保 panic 被限制并记录日志,而不是导致进程崩溃。 Panic 安全的异步卡片操作执行序列图sequenceDiagram
actor User
participant LarkCallback as CardActionDispatch
participant AsyncTask as AsyncTask
participant Logger as logs
User->>LarkCallback: Dispatch(ctx, event, metaData)
LarkCallback->>AsyncTask: runAsyncTask(context.WithoutCancel(ctx), action.Name, task)
activate AsyncTask
AsyncTask->>AsyncTask: task(ctx)
alt [panic occurs]
AsyncTask->>Logger: logs.L().Ctx(ctx).Error("panic in async card action")
end
deactivate AsyncTask
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your Experience访问你的控制面板 来:
Getting HelpOriginal review guide in EnglishReviewer's GuideAdds a panic-safe wrapper around asynchronous card action tasks and a regression test to ensure panics are contained and logged instead of crashing the process. Sequence diagram for panic-safe async card action executionsequenceDiagram
actor User
participant LarkCallback as CardActionDispatch
participant AsyncTask as AsyncTask
participant Logger as logs
User->>LarkCallback: Dispatch(ctx, event, metaData)
LarkCallback->>AsyncTask: runAsyncTask(context.WithoutCancel(ctx), action.Name, task)
activate AsyncTask
AsyncTask->>AsyncTask: task(ctx)
alt [panic occurs]
AsyncTask->>Logger: logs.L().Ctx(ctx).Error("panic in async card action")
end
deactivate AsyncTask
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
recoverboundary, allowing malformed/partial synthetic events to panic and terminate the whole process.Description
go task(context.WithoutCancel(ctx))call withgo runAsyncTask(context.WithoutCancel(ctx), action.Name, task)inDispatch(internal/application/lark/cardaction/registry.go).runAsyncTask(ctx, action, task)which defers arecover()and logs the recovered value plus the stack trace usinglogs.L().Ctx(ctx).Error(...)so panics are contained and observable.runtime/debug,github.com/BetaGoRobot/BetaGo-Redefine/pkg/logs,go.uber.org/zap).TestRunAsyncTaskRecoversPanicininternal/application/lark/cardaction/registry_test.gothat verifies a panic inside the async task does not escape the goroutine boundary.Testing
git diff --checkand appliedgofmt -won the modified files (both succeeded).fix(lark): recover async card action panics).go test ./internal/application/lark/cardaction ./internal/interfaces/larkbut full test execution is blocked in this environment due to the nativelibvips/bimgdependency required by other packages, so package-level integration tests could not be completed here.CGO_ENABLED=0 go test ./internal/application/lark/cardaction -run TestRunAsyncTaskRecoversPanicbut running tests in this container is constrained by native/CGO dependencies; the regression test was added and will run in CI where native dependencies are available.Codex Task
Summary by Sourcery
在异步 Lark 卡片操作任务中捕获 panic,防止其导致机器人崩溃,并改为产生可观察的错误日志。
Bug Fixes(错误修复):
Enhancements(增强):
Tests(测试):
runAsyncTask能够包含 panic,并阻止它们逃离 goroutine 边界。Original summary in English
Summary by Sourcery
Contain panics in asynchronous Lark card action tasks so they cannot crash the bot and instead produce observable error logs.
Bug Fixes:
Enhancements:
Tests: