Skip to content

fix: avoid ValueError when removing the active machine (#280)#281

Merged
knipknap merged 1 commit into
barebaric:mainfrom
MohammadYusif:fix/issue-280
Jun 6, 2026
Merged

fix: avoid ValueError when removing the active machine (#280)#281
knipknap merged 1 commit into
barebaric:mainfrom
MohammadYusif:fix/issue-280

Conversation

@MohammadYusif

Copy link
Copy Markdown
Contributor

Summary

  • Deleting the currently selected machine raised ValueError: No machine found with ID ... and left the UI stuck on the removed machine's settings until restart.
  • Root cause: MachineManager.remove_machine tears down the controller before emitting machine_removed. The cascading config-changed handler in MainWindow._on_machine_signals_changed then accesses self._current_machine.controller (lazily re-resolving through the already-emptied manager) and raises — aborting the handler before the UI refreshes.

Changes

  • rayforge/machine/models/manager.py: add has_controller(machine_id) — checks machine_id in self.controllers without lazily creating one; safe to call for removed machines.
  • rayforge/machine/models/machine.py: add Machine.has_controller property delegating to the manager.
  • rayforge/ui_gtk/mainwindow.py: guard laser_power_changed.disconnect(...) with if self._current_machine.has_controller: so an already-torn-down controller is skipped instead of crashing.
  • tests/machine/models/test_machine_manager.py: add test_has_controller_does_not_lazily_create and test_removed_machine_reports_no_controller (regression for Failure when removing currently selected machine #280 — asserts .controller raises ValueError without the guard, confirming the test is load-bearing).

Fixes #280

When the currently selected machine was deleted, MachineManager.remove_machine
tore down its controller before emitting machine_removed. The cascading
config-changed handler in MainWindow._on_machine_signals_changed then tried to
disconnect the controller's laser_power_changed signal via
self._current_machine.controller, which lazily re-resolves the controller
through the manager and raised "No machine found with ID ...". The unhandled
exception aborted the handler, leaving the UI stuck on the removed machine's
settings until restart.

Add a non-lazy has_controller check on MachineManager (and a matching
Machine.has_controller property) and guard the disconnect with it, so the
already-gone controller signal is simply skipped instead of crashing. This
fixes the root cause rather than swallowing the error.
@knipknap
knipknap merged commit bcb6bb1 into barebaric:main Jun 6, 2026
28 of 29 checks passed
@knipknap

knipknap commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Awesome, and with regression tests included - thank you!

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.

Failure when removing currently selected machine

2 participants