🥅 analysis: detect invalid analysis and produce error log

See #3930
This commit is contained in:
Gina Häußge committed 2021-01-25 15:43:05 +01:00
1 parent 7f3baa3b1e
commit 4531f44ed5
2 files changed
+54 -1

No files matched your search

+46
View File
@@ -4,6 +4,8 @@ from __future__ import absolute_import, division, print_function, unicode_litera
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
__copyright__ = "Copyright (C) 2017 The OctoPrint Project - Released under terms of the AGPLv3 License"
import sys
import click
click.disable_unicode_literals_warning = True
@@ -11,6 +13,40 @@ click.disable_unicode_literals_warning = True
# ~~ "octoprint util" commands
def validate_result(result):
dimensions = ("depth", "height", "width")
printing_area = ("maxX", "maxY", "maxZ", "minX", "minY", "minZ")
def validate_list(data):
return not any(map(invalid_float, data))
def validate_dict(data, keys):
for k in keys:
if k not in data or invalid_float(data[k]):
return False
return True
def invalid_float(value):
return value is None or value == float("inf") or value == float("-inf")
if "dimensions" not in result or not validate_dict(result["dimensions"], dimensions):
return False
if "extrusion_length" not in result or not validate_list(result["extrusion_length"]):
return False
if "extrusion_volume" not in result or not validate_list(result["extrusion_volume"]):
return False
if "printing_area" not in result or not validate_dict(
result["printing_area"], printing_area
):
return False
if "total_time" not in result or invalid_float(result["total_time"]):
return False
@click.group()
def analysis_commands():
pass
@@ -92,6 +128,16 @@ def gcode_command(
)
click.echo("DONE:{}s".format(monotonic_time() - start_time))
result = interpreter.get_result()
if not validate_result(result):
click.echo(
"ERROR:Invalid analysis result, please create a bug report in OctoPrint's "
"issue tracker and be sure to also include the GCODE file with which this "
"happened"
)
sys.exit(-1)
click.echo("RESULTS:")
click.echo(
yaml.safe_dump(
+8 -1
View File
@@ -319,6 +319,10 @@ class AbstractAnalysisQueue(object):
)
)
self._finished_callback(self._current, result)
except RuntimeError as exc:
self._logger.error(
"Analysis for {} ran into error: {}".format(self._current, exc)
)
finally:
self._current = None
self._current_progress = None
@@ -477,7 +481,10 @@ class GcodeAnalysisQueue(AbstractAnalysisQueue):
output = p.stdout.text
self._logger.debug("Got output: {!r}".format(output))
if "RESULTS:" not in output:
if "ERROR:" in output:
_, error = output.split("ERROR:")
raise RuntimeError(error.strip())
elif "RESULTS:" not in output:
raise RuntimeError("No analysis result found")
_, output = output.split("RESULTS:")