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.dump_debug()
|
||||
if self.is_fileinput:
|
||||
self.printer.request_exit()
|
||||
self.printer.request_exit('error_exit')
|
||||
return
|
||||
if state != 'ready':
|
||||
return
|
||||
|
@ -264,6 +264,8 @@ class GCodeParser:
|
|||
if len(lines) > 1:
|
||||
self.respond_info("\n".join(lines))
|
||||
self.respond('!! %s' % (lines[0].strip(),))
|
||||
if self.is_fileinput:
|
||||
self.printer.request_exit('error_exit')
|
||||
# Parameter parsing helpers
|
||||
class sentinel: pass
|
||||
def get_str(self, name, params, default=sentinel, parser=str,
|
||||
|
|
|
@ -150,6 +150,11 @@ class Printer:
|
|||
return self.reactor
|
||||
def get_state_message(self):
|
||||
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):
|
||||
if obj in self.objects:
|
||||
raise self.config_error(
|
||||
|
@ -236,7 +241,7 @@ class Printer:
|
|||
if self.state_message is not message_startup:
|
||||
return self.reactor.NEVER
|
||||
cb('connect')
|
||||
self.state_message = message_ready
|
||||
self._set_state(message_ready)
|
||||
for cb in self.state_cb:
|
||||
if self.state_message is not message_ready:
|
||||
return self.reactor.NEVER
|
||||
|
@ -245,17 +250,17 @@ class Printer:
|
|||
self.reactor.update_timer(self.stats_timer, self.reactor.NOW)
|
||||
except (self.config_error, pins.error) as e:
|
||||
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:
|
||||
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:
|
||||
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:
|
||||
logging.exception("Unhandled exception during connect")
|
||||
self.state_message = "Internal error during connect.%s" % (
|
||||
message_restart,)
|
||||
self._set_state("Internal error during connect.%s" % (
|
||||
message_restart,))
|
||||
return self.reactor.NEVER
|
||||
def run(self):
|
||||
systime = time.time()
|
||||
|
@ -268,7 +273,7 @@ class Printer:
|
|||
self.reactor.run()
|
||||
except:
|
||||
logging.exception("Unhandled exception during run")
|
||||
return "exit"
|
||||
return "error_exit"
|
||||
# Check restart flags
|
||||
run_result = self.run_result
|
||||
try:
|
||||
|
@ -288,13 +293,13 @@ class Printer:
|
|||
if self.is_shutdown:
|
||||
return
|
||||
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:
|
||||
cb('shutdown')
|
||||
def invoke_async_shutdown(self, msg):
|
||||
self.async_shutdown_msg = msg
|
||||
self.request_exit("shutdown")
|
||||
def request_exit(self, result="exit"):
|
||||
def request_exit(self, result):
|
||||
self.run_result = result
|
||||
self.reactor.end()
|
||||
|
||||
|
@ -368,7 +373,7 @@ def main():
|
|||
bglogger.set_rollover_info('versions', versions)
|
||||
printer = Printer(input_fd, bglogger, start_args)
|
||||
res = printer.run()
|
||||
if res == 'exit':
|
||||
if res in ['exit', 'error_exit']:
|
||||
break
|
||||
time.sleep(1.)
|
||||
logging.info("Restarting printer")
|
||||
|
@ -377,5 +382,8 @@ def main():
|
|||
if bglogger is not None:
|
||||
bglogger.stop()
|
||||
|
||||
if res == 'error_exit':
|
||||
sys.exit(-1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue