mirror of
				https://github.com/Klipper3d/klipper.git
				synced 2025-10-30 01:35:55 +01:00 
			
		
		
		
	homing: Prefer printer.command_error() instead of homing.CommandError()
Update callers to use the printer.command_error reference instead of directly using homing.CommandError() when raising or catching errors. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
		| @@ -3,7 +3,6 @@ | |||||||
| # Copyright (C) 2019  Kevin O'Connor <kevin@koconnor.net> | # Copyright (C) 2019  Kevin O'Connor <kevin@koconnor.net> | ||||||
| # | # | ||||||
| # This file may be distributed under the terms of the GNU GPLv3 license. | # This file may be distributed under the terms of the GNU GPLv3 license. | ||||||
| import homing |  | ||||||
|  |  | ||||||
| def parse_coord(config, param): | def parse_coord(config, param): | ||||||
|     pair = config.get(param).strip().split(',', 1) |     pair = config.get(param).strip().split(',', 1) | ||||||
|   | |||||||
| @@ -4,7 +4,6 @@ | |||||||
| # | # | ||||||
| # This file may be distributed under the terms of the GNU GPLv3 license. | # This file may be distributed under the terms of the GNU GPLv3 license. | ||||||
| import logging, bisect | import logging, bisect | ||||||
| import homing |  | ||||||
|  |  | ||||||
| class ManualProbe: | class ManualProbe: | ||||||
|     def __init__(self, config): |     def __init__(self, config): | ||||||
| @@ -97,7 +96,7 @@ class ManualProbeHelper: | |||||||
|             if curpos[2] < z_bob_pos: |             if curpos[2] < z_bob_pos: | ||||||
|                 self.toolhead.manual_move([None, None, z_bob_pos], self.speed) |                 self.toolhead.manual_move([None, None, z_bob_pos], self.speed) | ||||||
|             self.toolhead.manual_move([None, None, z_pos], self.speed) |             self.toolhead.manual_move([None, None, z_pos], self.speed) | ||||||
|         except homing.CommandError as e: |         except self.printer.command_error as e: | ||||||
|             self.finalize(False) |             self.finalize(False) | ||||||
|             raise |             raise | ||||||
|     def report_z_status(self, warn_no_change=False, prev_pos=None): |     def report_z_status(self, warn_no_change=False, prev_pos=None): | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ | |||||||
| # Copyright (C) 2019  Kevin O'Connor <kevin@koconnor.net> | # Copyright (C) 2019  Kevin O'Connor <kevin@koconnor.net> | ||||||
| # | # | ||||||
| # This file may be distributed under the terms of the GNU GPLv3 license. | # This file may be distributed under the terms of the GNU GPLv3 license. | ||||||
| import stepper, homing, chelper | import stepper, chelper | ||||||
| from . import force_move | from . import force_move | ||||||
|  |  | ||||||
| ENDSTOP_SAMPLE_TIME = .000015 | ENDSTOP_SAMPLE_TIME = .000015 | ||||||
| @@ -110,7 +110,7 @@ class ManualStepper: | |||||||
|                 error = str(e) |                 error = str(e) | ||||||
|         self.sync_print_time() |         self.sync_print_time() | ||||||
|         if error is not None: |         if error is not None: | ||||||
|             raise homing.CommandError(error) |             raise self.printer.command_error(error) | ||||||
|     cmd_MANUAL_STEPPER_help = "Command a manually configured stepper" |     cmd_MANUAL_STEPPER_help = "Command a manually configured stepper" | ||||||
|     def cmd_MANUAL_STEPPER(self, gcmd): |     def cmd_MANUAL_STEPPER(self, gcmd): | ||||||
|         enable = gcmd.get_int('ENABLE', None) |         enable = gcmd.get_int('ENABLE', None) | ||||||
|   | |||||||
| @@ -115,11 +115,11 @@ class PrinterProbe: | |||||||
|         try: |         try: | ||||||
|             homing_state.homing_move(pos, endstops, speed, |             homing_state.homing_move(pos, endstops, speed, | ||||||
|                                      probe_pos=True, verify_movement=verify) |                                      probe_pos=True, verify_movement=verify) | ||||||
|         except homing.CommandError as e: |         except self.printer.command_error as e: | ||||||
|             reason = str(e) |             reason = str(e) | ||||||
|             if "Timeout during endstop homing" in reason: |             if "Timeout during endstop homing" in reason: | ||||||
|                 reason += HINT_TIMEOUT |                 reason += HINT_TIMEOUT | ||||||
|             raise homing.CommandError(reason) |             raise self.printer.command_error(reason) | ||||||
|         pos = toolhead.get_position() |         pos = toolhead.get_position() | ||||||
|         self.gcode.respond_info("probe at %.3f,%.3f is z=%.6f" |         self.gcode.respond_info("probe at %.3f,%.3f is z=%.6f" | ||||||
|                                 % (pos[0], pos[1], pos[2])) |                                 % (pos[0], pos[1], pos[2])) | ||||||
| @@ -162,8 +162,7 @@ class PrinterProbe: | |||||||
|             z_positions = [p[2] for p in positions] |             z_positions = [p[2] for p in positions] | ||||||
|             if max(z_positions) - min(z_positions) > samples_tolerance: |             if max(z_positions) - min(z_positions) > samples_tolerance: | ||||||
|                 if retries >= samples_retries: |                 if retries >= samples_retries: | ||||||
|                     raise homing.CommandError( |                     raise gcmd.error("Probe samples exceed samples_tolerance") | ||||||
|                         "Probe samples exceed samples_tolerance") |  | ||||||
|                 gcmd.respond_info("Probe samples exceed tolerance. Retrying...") |                 gcmd.respond_info("Probe samples exceed tolerance. Retrying...") | ||||||
|                 retries += 1 |                 retries += 1 | ||||||
|                 positions = [] |                 positions = [] | ||||||
| @@ -295,14 +294,14 @@ class ProbeEndstopWrapper: | |||||||
|         start_pos = toolhead.get_position() |         start_pos = toolhead.get_position() | ||||||
|         self.activate_gcode.run_gcode_from_command() |         self.activate_gcode.run_gcode_from_command() | ||||||
|         if toolhead.get_position()[:3] != start_pos[:3]: |         if toolhead.get_position()[:3] != start_pos[:3]: | ||||||
|             raise homing.CommandError( |             raise self.printer.command_error( | ||||||
|                 "Toolhead moved during probe activate_gcode script") |                 "Toolhead moved during probe activate_gcode script") | ||||||
|     def probe_finish(self): |     def probe_finish(self): | ||||||
|         toolhead = self.printer.lookup_object('toolhead') |         toolhead = self.printer.lookup_object('toolhead') | ||||||
|         start_pos = toolhead.get_position() |         start_pos = toolhead.get_position() | ||||||
|         self.deactivate_gcode.run_gcode_from_command() |         self.deactivate_gcode.run_gcode_from_command() | ||||||
|         if toolhead.get_position()[:3] != start_pos[:3]: |         if toolhead.get_position()[:3] != start_pos[:3]: | ||||||
|             raise homing.CommandError( |             raise self.printer.command_error( | ||||||
|                 "Toolhead moved during probe deactivate_gcode script") |                 "Toolhead moved during probe deactivate_gcode script") | ||||||
|     def get_position_endstop(self): |     def get_position_endstop(self): | ||||||
|         return self.position_endstop |         return self.position_endstop | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
| # | # | ||||||
| # This file may be distributed under the terms of the GNU GPLv3 license. | # This file may be distributed under the terms of the GNU GPLv3 license. | ||||||
| import math, logging | import math, logging | ||||||
| import stepper, homing, chelper | import stepper, chelper | ||||||
|  |  | ||||||
| class PrinterExtruder: | class PrinterExtruder: | ||||||
|     def __init__(self, config, extruder_num): |     def __init__(self, config, extruder_num): | ||||||
| @@ -214,6 +214,8 @@ class PrinterExtruder: | |||||||
|  |  | ||||||
| # Dummy extruder class used when a printer has no extruder at all | # Dummy extruder class used when a printer has no extruder at all | ||||||
| class DummyExtruder: | class DummyExtruder: | ||||||
|  |     def __init__(self, printer): | ||||||
|  |         self.printer = printer | ||||||
|     def update_move_time(self, flush_time): |     def update_move_time(self, flush_time): | ||||||
|         pass |         pass | ||||||
|     def check_move(self, move): |     def check_move(self, move): | ||||||
| @@ -223,7 +225,7 @@ class DummyExtruder: | |||||||
|     def get_name(self): |     def get_name(self): | ||||||
|         return "" |         return "" | ||||||
|     def get_heater(self): |     def get_heater(self): | ||||||
|         raise homing.CommandError("Extruder not configured") |         raise self.printer.command_error("Extruder not configured") | ||||||
|  |  | ||||||
| def add_printer_objects(config): | def add_printer_objects(config): | ||||||
|     printer = config.get_printer() |     printer = config.get_printer() | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
| # | # | ||||||
| # This file may be distributed under the terms of the GNU GPLv3 license. | # This file may be distributed under the terms of the GNU GPLv3 license. | ||||||
| import math, logging, collections | import math, logging, collections | ||||||
| import homing, chelper | import chelper | ||||||
|  |  | ||||||
| class error(Exception): | class error(Exception): | ||||||
|     pass |     pass | ||||||
|   | |||||||
| @@ -250,7 +250,7 @@ class ToolHead: | |||||||
|         self.trapq_free_moves = ffi_lib.trapq_free_moves |         self.trapq_free_moves = ffi_lib.trapq_free_moves | ||||||
|         self.step_generators = [] |         self.step_generators = [] | ||||||
|         # Create kinematics class |         # Create kinematics class | ||||||
|         self.extruder = kinematics.extruder.DummyExtruder() |         self.extruder = kinematics.extruder.DummyExtruder(self.printer) | ||||||
|         kin_name = config.get('kinematics') |         kin_name = config.get('kinematics') | ||||||
|         try: |         try: | ||||||
|             mod = importlib.import_module('kinematics.' + kin_name) |             mod = importlib.import_module('kinematics.' + kin_name) | ||||||
| @@ -470,7 +470,7 @@ class ToolHead: | |||||||
|         # Submit move |         # Submit move | ||||||
|         try: |         try: | ||||||
|             self.move(newpos, speed) |             self.move(newpos, speed) | ||||||
|         except homing.CommandError as e: |         except self.printer.command_error as e: | ||||||
|             self.flush_step_generation() |             self.flush_step_generation() | ||||||
|             raise |             raise | ||||||
|         # Transmit move in "drip" mode |         # Transmit move in "drip" mode | ||||||
|   | |||||||
| @@ -228,7 +228,7 @@ class ClientConnection: | |||||||
|         try: |         try: | ||||||
|             func = self.webhooks.get_callback(web_request.get_method()) |             func = self.webhooks.get_callback(web_request.get_method()) | ||||||
|             func(web_request) |             func(web_request) | ||||||
|         except homing.CommandError as e: |         except self.printer.command_error as e: | ||||||
|             web_request.set_error(WebRequestError(e.message)) |             web_request.set_error(WebRequestError(e.message)) | ||||||
|         except Exception as e: |         except Exception as e: | ||||||
|             msg = ("Internal Error on WebRequest: %s" |             msg = ("Internal Error on WebRequest: %s" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user