Fix bug when default_extruder_nr is not provided

Then this would not slice because of a KeyError that is not caught.

Contributes to issue CURA-5457.
This commit is contained in:
Ghostkeeper 2018-07-05 12:51:27 +02:00
parent ef2250b889
commit 8f8c515438
No known key found for this signature in database
GPG key ID: 5252B696FB5E7C7A

View file

@ -41,14 +41,11 @@ class StartJobResult(IntEnum):
## Formatter class that handles token expansion in start/end gcode
class GcodeStartEndFormatter(Formatter):
def get_value(self, key: str, *args: str, **kwargs) -> str: #type: ignore # [CodeStyle: get_value is an overridden function from the Formatter class]
def get_value(self, key: str, *args: str, default_extruder_nr: str = "-1", **kwargs) -> str: #type: ignore # [CodeStyle: get_value is an overridden function from the Formatter class]
# The kwargs dictionary contains a dictionary for each stack (with a string of the extruder_nr as their key),
# and a default_extruder_nr to use when no extruder_nr is specified
try:
extruder_nr = int(kwargs["default_extruder_nr"])
except ValueError:
extruder_nr = -1
extruder_nr = int(default_extruder_nr)
key_fragments = [fragment.strip() for fragment in key.split(",")]
if len(key_fragments) == 2:
@ -56,7 +53,7 @@ class GcodeStartEndFormatter(Formatter):
extruder_nr = int(key_fragments[1])
except ValueError:
try:
extruder_nr = int(kwargs["-1"][key_fragments[1]]) # get extruder_nr values from the global stack
extruder_nr = int(kwargs["-1"][key_fragments[1]]) # get extruder_nr values from the global stack #TODO: How can you ever provide the '-1' kwarg?
except (KeyError, ValueError):
# either the key does not exist, or the value is not an int
Logger.log("w", "Unable to determine stack nr '%s' for key '%s' in start/end g-code, using global stack", key_fragments[1], key_fragments[0])