Repository navigation
fix(worktree-palette): guard undefined review title in matcher (crash c5d87873) - #10024
Conversation
… c5d87873) matchWorktreePaletteReview called review.title.toLowerCase() with no guard. Rehydrated review/PR caches can hold entries with an undefined title, so any text query in the Cmd/Ctrl+J worktree palette crashed the renderer with 'TypeError: Cannot read properties of undefined (reading toLowerCase)'. Coalesce the title to '' and widen the type to reflect runtime reality. Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughUpdated 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 46f849d7-dfb7-4f81-be82-0233a99ef000
📒 Files selected for processing (2)
src/renderer/src/lib/worktree-palette-review-match.test.tssrc/renderer/src/lib/worktree-palette-review-match.ts
| // Null-safe: a cached review may have no title, so fall back to '' (query is non-empty, so it won't match). | ||
| const title = review.title ?? '' | ||
| const titleIndex = title.toLowerCase().indexOf(query) | ||
| if (titleIndex === -1) { | ||
| return null | ||
| } | ||
| return { | ||
| labelKind: isMergeRequest ? 'mr' : 'pr', | ||
| text: review.title, | ||
| text: title, |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Return no match explicitly when the title is missing.
With query === '', the empty fallback produces titleIndex === 0, so a titleless review returns a match with empty text instead of null. Guard the missing-title case directly and add an empty-query regression test.
Suggested fix
- // Null-safe: a cached review may have no title, so fall back to '' (query is non-empty, so it won't match).
- const title = review.title ?? ''
+ if (review.title == null) {
+ return null
+ }
+ const title = review.title📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Null-safe: a cached review may have no title, so fall back to '' (query is non-empty, so it won't match). | |
| const title = review.title ?? '' | |
| const titleIndex = title.toLowerCase().indexOf(query) | |
| if (titleIndex === -1) { | |
| return null | |
| } | |
| return { | |
| labelKind: isMergeRequest ? 'mr' : 'pr', | |
| text: review.title, | |
| text: title, | |
| if (review.title == null) { | |
| return null | |
| } | |
| const title = review.title | |
| const titleIndex = title.toLowerCase().indexOf(query) | |
| if (titleIndex === -1) { | |
| return null | |
| } | |
| return { | |
| labelKind: isMergeRequest ? 'mr' : 'pr', | |
| text: title, |
… c5d87873) (stablyai#10024) Co-authored-by: Orca <[email protected]>
Description
Fixes a renderer crash in the Worktree Jump Palette (
Cmd/Ctrl+J). Typing any non-numeric text into the palette could throw:matchWorktreePaletteReviewcalledreview.title.toLowerCase()with no guard. AlthoughHostedReviewInfo.title/PRInfo.titleare typed as requiredstring, the review objects come from on-disk rehydrated caches (hostedReviewCache/prCache) that can contain partial/legacy entries with notitle. At runtimetitlewasundefined, so the whole renderer crashed into themodal.worktree-paletteerror boundary.Crash report:
c5d87873-e664-405e-858e-c41a720d50b5(macOS, Orca 1.4.147). Same unguarded path exists on currentmain.CLEAR, UNDENIABLE fix evidence
A regression test reproduces the exact production error against the unmodified code, then passes after the one-line null-safety guard.
Before the fix (
git stashthe source change, keep the test):The thrown message is byte-for-byte the production crash, reproduced both through the matcher directly and through the real
searchWorktrees→WorktreeJumpPaletteuseMemopath from the stack trace.After the fix:
tscweb typecheck: exit 0.oxlinton the changed file: clean.ELI5
The little "jump to worktree" search box tries to match what you type against each worktree's pull-request title. Some saved PR records (loaded from disk) had no title at all — an empty slot. The code assumed a title was always there and called "make this text lowercase" on the empty slot, which is like trying to read a page from a book that isn't there — so the whole window crashed. The fix: if there's no title, treat it as an empty string. An empty title just can't match your search (which is correct — there's nothing to match), and nothing crashes.
Trade-offs / regressions
null(no supporting-text highlight for that review) instead of throwing — the desired behavior; the palette simply doesn't highlight a title that never existed. Number matching, GitHub/GitLab sigil scoping, and match-range math are untouched.SearchableReviewtype was narrowed totitle?: string(honest about runtime reality); all call sites still compile.HostedReviewInfo.title: stringis still "optimistic" — any other consumer that reads a rehydrated title directly could hit the same class of bug. This PR guards the crashing palette path only. A follow-up could maketitleoptional at the type source or sanitize on cache rehydration.Adversarial review
null; the type widening is sound; no title-present behavior change; no secondary.titlecrash remains in theuseMemopath). Only nice-to-have/nit suggestions remained (the deferred schema note above; a non-string-title defensive coercion with no evidence of occurring) — none are must-fix./perfskill, sub-agent): clean. Pure null-safety guard; if anything it reduces two property reads to one. No allocation, polling, effect, render, or subscription vectors touched.Made with Orca 🐋