fix: replace non-null assertions on find() with proper null checks#11723
Open
zerone0x wants to merge 1 commit intoanomalyco:devfrom
Open
fix: replace non-null assertions on find() with proper null checks#11723zerone0x wants to merge 1 commit intoanomalyco:devfrom
zerone0x wants to merge 1 commit intoanomalyco:devfrom
Conversation
Replace unsafe `find()!` patterns that crash at runtime when the search predicate doesn't match. Each location now handles the missing case appropriately: fallback to first agent in TUI, descriptive errors in provider/compaction, early return in summary, and 400 response in TUI event route. Fixes anomalyco#11702 Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
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.
What does this PR do?
Replaces 5 unsafe
find()!non-null assertion patterns across the codebase with proper null checks. These patterns crash at runtime with "Cannot read property of undefined" when the search predicate doesn't match any element.The most impactful fix is in
local.tsx, which is the direct cause of the fatal TUI crash reported in #11262 ("Cannot read property 'name' of undefined").Each location is handled with an appropriate strategy for its context:
local.tsx:57— Falls back to first agent and updates store (prevents TUI fatal crash)provider.ts:1051— Throws descriptive error if provider module has nocreate*exportcompaction.ts:99— Throws descriptive error if parent message is missingsummary.ts:124— Logs warning and returns early if message not foundtui.ts:348— Returns 400 if event type not found (defensive, Zod should prevent this)Fixes #11702
How did you verify your code works?
tsgo --noEmit— typecheck passes across all 12 packagesbun test— 835 tests pass (5 pre-existing failures in llm.test.ts/retry.test.ts unrelated to this change)bun run build— builds successfully for all platforms