fix: return a result instead of throwing when the host passes no context - #24
Merged
Conversation
`execute` declares `context: ToolContext` (non-nullable), but MulmoClaude's server bridge passes null. Reading `context.app` unguarded threw `Cannot read properties of null (reading 'app')`, which surfaced as an HTTP 500 for every call. Widen the parameter to `ToolContext | null | undefined` and guard the dereference, so the plugin returns its existing "not available" result. Adds a regression test covering null / undefined / empty context. refs receptron/mulmoclaude#2709, receptron/mulmoclaude#2758 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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.
Summary
host が
execute()に null の context を渡すためクラッシュしていたのを修正した。receptron/mulmoclaude#2709 と同じ原因で、調査の結果 14 プラグインが同じ問題を抱えていた
(receptron/mulmoclaude#2758 に横断報告)。
Items to Confirm / Review
gui-chat-protocolのexecute: (context: ToolContext, args: A) => ...は context を non-nullable と宣言しているが、MulmoClaude の server bridge は実際には null を渡す。型が嘘をついているのでガードを書く動機が無かった。
プロトコル側の型修正を #2758 で提案している。
contextをToolContext | null | undefinedに広げ、src/core/plugin.ts:28の参照を?.でガードしただけ。ガード後の呼び出し(
context.app.xxx(...)等)はそのまま残してある。TypeScript が optional chaining 経由でnarrowing してくれるうえ、メソッド呼び出しの形を保つことで
this束縛を壊さないため。tests/plugin.test.ts。修正を戻すと実際に fail することを確認済み(テストが常に通るだけの飾りになっていない)。
変更内容
src/core/plugin.ts— context を nullable にし、src/core/plugin.ts:28をガードtests/plugin.test.ts— null / undefined / 空オブジェクトの 3 ケースpackage.json—testscript とtsx(MindMap の修正と同じ構成)、patch version bump.github/workflows/pull_request.yaml— CI でyarn testを実行eslint.config.js—tests/**を lint 対象外に(ガイド §3: 型プログラムを小さく保つ)検証
node_modulesを消してからのクリーン install で確認済み(warm な node_modules は lockfile 変更後の CI を再現しないため):
さらに
execute(null, args)を直接呼んで、修正前はTypeError、修正後は正常なToolResult が返ることを実機で確認した。
🤖 Generated with Claude Code