Skip to content

♻️ Replace SystemExit with structured errors in admin CLI#252

Open
Gudsfile wants to merge 4 commits into
mainfrom
refactor/phase-3-admin-cli-boundaries
Open

♻️ Replace SystemExit with structured errors in admin CLI#252
Gudsfile wants to merge 4 commits into
mainfrom
refactor/phase-3-admin-cli-boundaries

Conversation

@Gudsfile
Copy link
Copy Markdown
Owner

@Gudsfile Gudsfile commented May 5, 2026

Summary

Improve CLI error handling by replacing SystemExit-based flows with explicit Exception or Typer-native mechanisms.

  • Introduce MissingOptionalDependencyError to replace SystemExit(str) previously raised by _raise_optional_extra_error and propagated through the CLI adapter.
  • Replace _exit_on_command_validation_error with a new _exit_error helper using typer.echo and typer.Exit instead of SystemExit(str).
  • Add _exit_success to mirror _exit_error for consistent success exits.
  • Move optional_extra_dependency_message into MissingOptionalDependencyError as an install_hint property and align the pn532, API and UI adapters to use it.

Test plan

  • uv sync to remove extra
  • uv run --extra ui pytest
  • uv run jukebox-admin api -> concise install hint
  • uv run jukebox-admin --verbose api -> install hint
  • uv run --extra api jukebox-admin api -> works
  • uv run jukebox --reader pn532 -> stack trace with the install hint (improving the case display is not within the scope of this PR)

Out of scope

Does not suppress the SystemExit of the jukebox CLI (it's done in #254).

@Gudsfile Gudsfile self-assigned this May 5, 2026
@Gudsfile Gudsfile force-pushed the refactor/phase-3-admin-cli-boundaries branch 2 times, most recently from 483d022 to 1ad5b63 Compare May 5, 2026 23:36
@Gudsfile Gudsfile force-pushed the refactor/phase-2b-settings-sonos-page-builder-tests branch from 0b399fb to 23f32c6 Compare May 7, 2026 16:20
@Gudsfile Gudsfile force-pushed the refactor/phase-3-admin-cli-boundaries branch from 1ad5b63 to 82f5b2d Compare May 7, 2026 16:21
Base automatically changed from refactor/phase-2b-settings-sonos-page-builder-tests to main May 7, 2026 16:55
@Gudsfile Gudsfile force-pushed the refactor/phase-3-admin-cli-boundaries branch 4 times, most recently from ec69ef0 to 6d1af7b Compare May 7, 2026 22:44
@Gudsfile Gudsfile marked this pull request as ready for review May 7, 2026 22:50
@Gudsfile Gudsfile force-pushed the refactor/phase-3-admin-cli-boundaries branch from 6d1af7b to 232695c Compare May 8, 2026 10:11
Gudsfile added 4 commits May 12, 2026 23:42
Move MissingOptionalDependencyError from jukebox/admin/errors.py to jukebox/shared/errors.py so all adapters (pn532, api, ui, admin) can raise a single structured error type
Absorb optional_extra_dependency_message into the class as an install_hint property and delete dependency_messages.py.
@msgerbush msgerbush force-pushed the refactor/phase-3-admin-cli-boundaries branch from 232695c to 37db220 Compare May 13, 2026 03:42
Copy link
Copy Markdown
Collaborator

@msgerbush msgerbush left a comment

Choose a reason for hiding this comment

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

One small issue, otherwise looks good to me!

try:
from pn532 import PN532_SPI
except ModuleNotFoundError as err:
raise ModuleNotFoundError(optional_extra_dependency_message("The `pn532` reader", "pn532", "jukebox ...")) from err
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this is going to cause an issue in pn532_command_handlers.py, since we were specifically handling ModuleNotFoundError

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.

2 participants