Skip to content

fix(cli): return an error instead of panicking on empty play results - #633

Merged
LargeModGames merged 1 commit into
LargeModGames:mainfrom
kapok-4o:fix/cli-play-empty-results
Sep 27, 2026
Merged

LargeModGames merged 1 commit into
LargeModGames:mainfrom
kapok-4o:fix/cli-play-empty-results

Conversation

@kapok-4o

@kapok-4o kapok-4o commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #603.

  • play now calls a pure first_result_uri(&SearchResult, &Type, &str), which uses first() instead of items[0]. An empty page and a None page both return the existing no <type>s with name '...' error, and a hit without an id keeps its ... has no id error. The app lock stays inside its own block.
  • play_uri uses random_offset(total), which is None for 0. On None it calls handle_error(anyhow!("playlist has no tracks")) and returns, like the fetch error branch.
  • query treats an empty page like None in all five arms, so spotatui search with no hits prints no tracks with name '...' instead of a blank line.
  • No println!/eprintln! added.

Tests in src/cli/cli_app.rs cover the cases in the issue (empty track and playlist pages, first track and playlist hit, random_offset), plus empty and missing pages for albums, artists and shows, the type of each hit, and the missing-id errors.

Testing

  • cargo fmt --all -- --check: clean
  • cargo clippy --no-default-features --features telemetry,tui -- -D warnings: clean
  • cargo test --no-default-features --features telemetry,tui: 1291 passed, 0 failed
  • cargo test --no-default-features --features telemetry,tui cli_app: 11 passed
  • With items[0] back in the track arm and random_range(0..total) back without the guard, play_by_name_reports_no_tracks_when_the_search_page_is_empty and a_random_offset_into_an_empty_playlist_is_none fail.

Additional notes

I didn't run the CLI against a real account.

This is one of five small PRs I opened together (#602, #603, #594, #595, #599). Each changelog entry sits at a different spot in [Unreleased] so they merge without conflicts in any order.

Written with AI coding assistants: the fix was drafted by Codex, then extracted onto its own branch, checked against the issue and re-tested by Claude Code.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Playing a random track from an empty playlist now returns an error instead of causing the app to crash.
    • Searches with no results now display a clear “no results” message rather than a blank line.
    • Playback searches continue to select the first matching result across tracks, albums, artists, shows, and playlists.

A search with no hits stores an empty page, not None, so `play -n`
indexed items[0] and panicked, and `play -u <empty playlist> -r` asked
rand for a value in 0..0. Pull the lookup into first_result_uri, which
uses first() and keeps the existing "no <type>s with name" and "has no
id" errors, add random_offset, and treat an empty page like None in
query.

Fixes LargeModGames#603

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: LargeModGames/spotatui/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 7c55fc94-ad61-4f94-9472-77f3dba63ba9

📥 Commits

Reviewing files that changed from the base of the PR and between 7c21df0 and aa628b0.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • src/cli/cli_app.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The CLI now returns errors when playback uses an empty search result or an empty playlist for random selection. Search commands return their existing no-results messages when a result page is empty.

Changes

CLI empty-result handling

Layer / File(s) Summary
Playback selection and empty playlists
src/cli/cli_app.rs
play selects the first available result for tracks, albums, artists, shows, and playlists. Missing results or IDs return type-specific errors. Random playback on an empty playlist reports an error. Tests cover result selection and random offsets.
Empty search output
src/cli/cli_app.rs, CHANGELOG.md
Search commands for playlists, tracks, artists, shows, and albums return their existing no-results messages when a page is missing or empty. The changelog records these changes.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to aa628

The empty-result handling is mergeable after normal checks; no actionable issue remains identified.


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Linked Issues check ❌ Error Issue #603 objectives are implemented in src/cli/cli_app.rs: first_result_uri uses .first() for all five search types, query rejects empty pages, and random_offset(0) reports `playlist has n… Update tools/gates.count so test_attribute_total increases by 10 for the new tests. Rerun the required slim-feature test, formatting, Clippy, and full test commands.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses the permitted fix(cli): prefix, is concise and imperative, and accurately describes the empty play-result error fix. It does not mention every related search-result change, but it cle…
Out of Scope Changes check ✅ Passed The changed files stay within issue #603. The CLI changes fix empty search pages and empty-playlist random playback. The added unit tests verify those behaviors. The changelog entry documents the same…
Full details: Linked Issues check

Explanation

Issue #603 objectives are implemented in src/cli/cli_app.rs: first_result_uri uses .first() for all five search types, query rejects empty pages, and random_offset(0) reports playlist has no tracks through handle_error. Focused tests cover empty and missing pages, first-hit selection, missing IDs, and random offsets. However, the diff adds 10 new #[test] functions and does not update tools/gates.count, although issue #603 requires test_attribute_total to increase for each new test. The reported test pass does not establish that this required gate-count update is present.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
✨ Simplify code
  • Create a new PR

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.

@codecov

codecov Bot commented Sep 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.71041% with 36 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/cli/cli_app.rs 83.7% 36 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-merge checks failed. Please resolve the failing checks before merging.

@kapok-4o

Copy link
Copy Markdown
Collaborator Author

The floors in tools/gates.count are minimums since #626, so the ratchet passes without a bump, and bumping the same line in each of my open PRs would make them conflict with each other. I left it for the next floor raise.

@LargeModGames
LargeModGames merged commit 52562d1 into LargeModGames:main Sep 27, 2026
31 checks passed
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.

CLI play panics on an empty search result or empty playlist

2 participants