Skip to content

fix(cli): reset track selection on disc rescan to prevent TypeError#15

Merged
Masterisk-F merged 2 commits into
masterfrom
fix/cli-stale-track-selection
Jul 19, 2026
Merged

fix(cli): reset track selection on disc rescan to prevent TypeError#15
Masterisk-F merged 2 commits into
masterfrom
fix/cli-stale-track-selection

Conversation

@Masterisk-F

Copy link
Copy Markdown
Owner

When the user rescans the disc (menu option 2) after having visited the track selection menu (option 4), the cached @selection in CliTracklist becomes stale. If the new disc has fewer tracks, the old track numbers cause @disc.getLengthSector(track) to return nil, producing:

TypeError: nil can't be coerced into Float

Fix by recreating @cliTracklist on rescan (same pattern as CliDisc#refreshDisc which creates Disc.new()). The new instance lazily initializes @selection from the current disc's track list, discarding any stale state.

This mirrors the GTK interface (GtkDisc#refreshDisc) which resets @selection = [] on every refresh.

Also add spec verifying that a freshly created CliTracklist returns the current disc's track list even when a previous instance had a different track count.

When the user rescans the disc (menu option 2) after having visited the
track selection menu (option 4), the cached @selection in CliTracklist
becomes stale. If the new disc has fewer tracks, the old track numbers
cause @disc.getLengthSector(track) to return nil, producing:

  TypeError: nil can't be coerced into Float

Fix by recreating @cliTracklist on rescan (same pattern as CliDisc#refreshDisc
which creates Disc.new()).  The new instance lazily initializes @selection
from the current disc's track list, discarding any stale state.

This mirrors the GTK interface (GtkDisc#refreshDisc) which resets
@selection = [] on every refresh.

Also add spec verifying that a freshly created CliTracklist returns the
current disc's track list even when a previous instance had a
different track count.
When the user selects option 2 (rescan drive) in the main menu,
scan errors (e.g. no disc in drive) were silently swallowed:
@cliDisc.show() stores the error in @cliDisc.error but never
displays it, unlike prepare() which calls showError() afterward.

Add the missing showError() call after @cliDisc.show() in the
loopMainMenu option 2 branch, matching the existing prepare()
pattern.

Also add a new spec file (spec/cli/commandLineInterface_spec.rb)
with a test case that verifies scan errors are displayed.
@Masterisk-F

Copy link
Copy Markdown
Owner Author

修正: リセキャン(オプション 2)のエラー黙殺問題に対応

問題

loopMainMenu の when 2 分岐で @cliDisc.show() を呼び出した後、スキャン失敗時のエラーがユーザーに表示されていませんでした。起動時のスキャン (prepare()) では showError() 呼び出しがありましたが、リセキャン時の同じパスでは欠落していました。ユーザーは空行だけを見てスキャンの成否を判断できません。

修正

when 2 に showError(@cliDisc.error) unless @cliDisc.error.nil? を追加。prepare() と同じパターンです。

テスト

spec/cli/commandLineInterface_spec.rb を新規作成。モック化した CliDisc がエラー [:noDiscYet, "3"] を返すシナリオで、showError が標準出力にメッセージを出力することを検証。

検証

  • spec/cli/ 全5件 通過 (0 failures)
  • 全 360件中 29 failures → 今回の変更による回帰なし(29件は pre-existing: codecs バイナリ不足、network 接続不可等)

@Masterisk-F
Masterisk-F merged commit c09fd6b into master Jul 19, 2026
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