klippy: Return an error code if batch input results in an error
When reading from a debug input file, propagate any errors to the program return status. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
efe63d5efe
commit
780e3c3022
|
@ -105,7 +105,7 @@ class GCodeParser:
|
||||||
self.gcode_handlers = self.base_gcode_handlers
|
self.gcode_handlers = self.base_gcode_handlers
|
||||||
self.dump_debug()
|
self.dump_debug()
|
||||||
if self.is_fileinput:
|
if self.is_fileinput:
|
||||||
self.printer.request_exit()
|
self.printer.request_exit('error_exit')
|
||||||
return
|
return
|
||||||
if state != 'ready':
|
if state != 'ready':
|
||||||
return
|
return
|
||||||
|
@ -264,6 +264,8 @@ class GCodeParser:
|
||||||
if len(lines) > 1:
|
if len(lines) > 1:
|
||||||
self.respond_info("\n".join(lines))
|
self.respond_info("\n".join(lines))
|
||||||
self.respond('!! %s' % (lines[0].strip(),))
|
self.respond('!! %s' % (lines[0].strip(),))
|
||||||
|
if self.is_fileinput:
|
||||||
|
self.printer.request_exit('error_exit')
|
||||||
# Parameter parsing helpers
|
# Parameter parsing helpers
|
||||||
class sentinel: pass
|
class sentinel: pass
|
||||||
def get_str(self, name, params, default=sentinel, parser=str,
|
def get_str(self, name, params, default=sentinel, parser=str,
|
||||||
|
|
|
@ -150,6 +150,11 @@ class Printer:
|
||||||
return self.reactor
|
return self.reactor
|
||||||
def get_state_message(self):
|
def get_state_message(self):
|
||||||
return self.state_message
|
return self.state_message
|
||||||
|
def _set_state(self, msg):
|
||||||
|
self.state_message = msg
|
||||||
|
if (msg != message_ready
|
||||||
|
and self.start_args.get('debuginput') is not None):
|
||||||
|
self.request_exit('error_exit')
|
||||||
def add_object(self, name, obj):
|
def add_object(self, name, obj):
|
||||||
if obj in self.objects:
|
if obj in self.objects:
|
||||||
raise self.config_error(
|
raise self.config_error(
|
||||||
|
@ -236,7 +241,7 @@ class Printer:
|
||||||
if self.state_message is not message_startup:
|
if self.state_message is not message_startup:
|
||||||
return self.reactor.NEVER
|
return self.reactor.NEVER
|
||||||
cb('connect')
|
cb('connect')
|
||||||
self.state_message = message_ready
|
self._set_state(message_ready)
|
||||||
for cb in self.state_cb:
|
for cb in self.state_cb:
|
||||||
if self.state_message is not message_ready:
|
if self.state_message is not message_ready:
|
||||||
return self.reactor.NEVER
|
return self.reactor.NEVER
|
||||||
|
@ -245,17 +250,17 @@ class Printer:
|
||||||
self.reactor.update_timer(self.stats_timer, self.reactor.NOW)
|
self.reactor.update_timer(self.stats_timer, self.reactor.NOW)
|
||||||
except (self.config_error, pins.error) as e:
|
except (self.config_error, pins.error) as e:
|
||||||
logging.exception("Config error")
|
logging.exception("Config error")
|
||||||
self.state_message = "%s%s" % (str(e), message_restart)
|
self._set_state("%s%s" % (str(e), message_restart))
|
||||||
except msgproto.error as e:
|
except msgproto.error as e:
|
||||||
logging.exception("Protocol error")
|
logging.exception("Protocol error")
|
||||||
self.state_message = "%s%s" % (str(e), message_protocol_error)
|
self._set_state("%s%s" % (str(e), message_protocol_error))
|
||||||
except mcu.error as e:
|
except mcu.error as e:
|
||||||
logging.exception("MCU error during connect")
|
logging.exception("MCU error during connect")
|
||||||
self.state_message = "%s%s" % (str(e), message_mcu_connect_error)
|
self._set_state("%s%s" % (str(e), message_mcu_connect_error))
|
||||||
except:
|
except:
|
||||||
logging.exception("Unhandled exception during connect")
|
logging.exception("Unhandled exception during connect")
|
||||||
self.state_message = "Internal error during connect.%s" % (
|
self._set_state("Internal error during connect.%s" % (
|
||||||
message_restart,)
|
message_restart,))
|
||||||
return self.reactor.NEVER
|
return self.reactor.NEVER
|
||||||
def run(self):
|
def run(self):
|
||||||
systime = time.time()
|
systime = time.time()
|
||||||
|
@ -268,7 +273,7 @@ class Printer:
|
||||||
self.reactor.run()
|
self.reactor.run()
|
||||||
except:
|
except:
|
||||||
logging.exception("Unhandled exception during run")
|
logging.exception("Unhandled exception during run")
|
||||||
return "exit"
|
return "error_exit"
|
||||||
# Check restart flags
|
# Check restart flags
|
||||||
run_result = self.run_result
|
run_result = self.run_result
|
||||||
try:
|
try:
|
||||||
|
@ -288,13 +293,13 @@ class Printer:
|
||||||
if self.is_shutdown:
|
if self.is_shutdown:
|
||||||
return
|
return
|
||||||
self.is_shutdown = True
|
self.is_shutdown = True
|
||||||
self.state_message = "%s%s" % (msg, message_shutdown)
|
self._set_state("%s%s" % (msg, message_shutdown))
|
||||||
for cb in self.state_cb:
|
for cb in self.state_cb:
|
||||||
cb('shutdown')
|
cb('shutdown')
|
||||||
def invoke_async_shutdown(self, msg):
|
def invoke_async_shutdown(self, msg):
|
||||||
self.async_shutdown_msg = msg
|
self.async_shutdown_msg = msg
|
||||||
self.request_exit("shutdown")
|
self.request_exit("shutdown")
|
||||||
def request_exit(self, result="exit"):
|
def request_exit(self, result):
|
||||||
self.run_result = result
|
self.run_result = result
|
||||||
self.reactor.end()
|
self.reactor.end()
|
||||||
|
|
||||||
|
@ -368,7 +373,7 @@ def main():
|
||||||
bglogger.set_rollover_info('versions', versions)
|
bglogger.set_rollover_info('versions', versions)
|
||||||
printer = Printer(input_fd, bglogger, start_args)
|
printer = Printer(input_fd, bglogger, start_args)
|
||||||
res = printer.run()
|
res = printer.run()
|
||||||
if res == 'exit':
|
if res in ['exit', 'error_exit']:
|
||||||
break
|
break
|
||||||
time.sleep(1.)
|
time.sleep(1.)
|
||||||
logging.info("Restarting printer")
|
logging.info("Restarting printer")
|
||||||
|
@ -377,5 +382,8 @@ def main():
|
||||||
if bglogger is not None:
|
if bglogger is not None:
|
||||||
bglogger.stop()
|
bglogger.stop()
|
||||||
|
|
||||||
|
if res == 'error_exit':
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue