fix: avoid ValueError when removing the active machine (#280)#281
Merged
Conversation
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.
Contributor
|
Awesome, and with regression tests included - thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ValueError: No machine found with ID ...and left the UI stuck on the removed machine's settings until restart.MachineManager.remove_machinetears down the controller before emittingmachine_removed. The cascading config-changed handler inMainWindow._on_machine_signals_changedthen accessesself._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: addhas_controller(machine_id)— checksmachine_id in self.controllerswithout lazily creating one; safe to call for removed machines.rayforge/machine/models/machine.py: addMachine.has_controllerproperty delegating to the manager.rayforge/ui_gtk/mainwindow.py: guardlaser_power_changed.disconnect(...)withif self._current_machine.has_controller:so an already-torn-down controller is skipped instead of crashing.tests/machine/models/test_machine_manager.py: addtest_has_controller_does_not_lazily_createandtest_removed_machine_reports_no_controller(regression for Failure when removing currently selected machine #280 — asserts.controllerraisesValueErrorwithout the guard, confirming the test is load-bearing).Fixes #280