Skip to content

fix: remove dangerous non-null assertions in compareGuitars#779

Open
nkar123412-hub wants to merge 1 commit into
TanStack:mainfrom
nkar123412-hub:fix/compare-guitars-safety
Open

fix: remove dangerous non-null assertions in compareGuitars#779
nkar123412-hub wants to merge 1 commit into
TanStack:mainfrom
nkar123412-hub:fix/compare-guitars-safety

Conversation

@nkar123412-hub

@nkar123412-hub nkar123412-hub commented Jun 17, 2026

Copy link
Copy Markdown

Removed dangerous non-null assertions () in tool implementation in the example. Added a check for empty selection and used optional chaining to prevent potential runtime crashes. Also improved the clarity of 'cheapest' labels.

This ensures that if the tool is called with invalid IDs, it throws a meaningful error instead of crashing the whole app.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling in guitar comparison to catch invalid guitar selections.
    • Enhanced price information display with "Unknown" fallback when pricing data is unavailable.
  • Improvements

    • Updated price difference labeling for clearer comparison messaging.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 921bb2b8-3266-4f0d-bb12-45abc1a87f41

📥 Commits

Reviewing files that changed from the base of the PR and between 8fa6cc5 and b7e3716.

📒 Files selected for processing (1)
  • examples/ts-react-chat/src/lib/guitar-tools.ts

📝 Walkthrough

Walkthrough

In compareGuitars's server implementation, a guard is added to throw when no provided guitarIds resolve to valid guitars. Two variables, cheapestGuitar and mostExpensiveGuitar, are derived from the selection's min/max prices and used to populate the cheapest/mostExpensive result fields with "Unknown" fallbacks. The priceDifference label is updated to use "in selection" wording.

Changes

compareGuitars result hardening

Layer / File(s) Summary
Empty-selection guard, price variables, and result wiring
examples/ts-react-chat/src/lib/guitar-tools.ts
Throws when the resolved guitar selection is empty; introduces cheapestGuitar/mostExpensiveGuitar from min/max prices; updates priceDifference label wording; replaces inline lookups with the precomputed variables using "Unknown" fallbacks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐇 Hop, hop through the strings and frets,
No empty selection — no regrets!
The cheapest guitar now has a name,
"Unknown" steps in to cover the game.
Min and max, all tidy and neat,
This bunny's code review is complete! 🎸

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description explains the changes and motivation, but does not include the required Checklist and Release Impact sections from the repository's template. Complete the PR description by adding the Checklist section (with testing confirmation) and Release Impact section (indicating whether this affects published code).
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically identifies the main change: removing dangerous non-null assertions in the compareGuitars tool, which aligns with the PR's primary objective of improving safety.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant