Skip to content

Commit

Permalink
🏴 Cleaner error if override points to unknown node
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier Torres authored and javitonino committed Jan 12, 2023
1 parent 217f54a commit b488b46
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/converter/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def convert(fig_instance):
return group.convert(fig_instance)

all_overrides = get_all_overrides(fig_instance)
sketch_overrides, unsupported = convert_overrides(all_overrides)
sketch_overrides, unsupported = convert_overrides(all_overrides, fig_instance)
if unsupported:
if config.can_detach:
utils.log_conversion_warning("SYM003", fig_instance, props=unsupported)
Expand Down Expand Up @@ -62,11 +62,11 @@ def master_instance(fig_symbol):
return obj


def convert_overrides(all_overrides):
def convert_overrides(all_overrides, fig_instance):
sketch_overrides = []
unsupported_overrides = []
for override in all_overrides:
sk, us = convert_override(override)
sk, us = convert_override(override, fig_instance)
sketch_overrides += sk
unsupported_overrides += us

Expand Down Expand Up @@ -119,16 +119,21 @@ def get_all_overrides(fig_instance):
return unique_overrides


def convert_override(override: dict) -> Tuple[List[OverrideValue], List[str]]:
def convert_override(override: dict, fig_instance: dict) -> Tuple[List[OverrideValue], List[str]]:
sketch_overrides = []
unsupported_overrides = []

# Convert uuids in the path from top symbol to child instance
sketch_path = [
utils.gen_object_id(context.fig_node(guid)["guid"])
for guid in override["guidPath"]["guids"]
]
sketch_path_str = "/".join(sketch_path)
try:
# Convert uuids in the path from top symbol to child instance
sketch_path = [
utils.gen_object_id(context.fig_node(guid)["guid"])
for guid in override["guidPath"]["guids"]
]
sketch_path_str = "/".join(sketch_path)
except KeyError as e:
# Cannot find where to apply override
utils.log_conversion_warning("SYM004", fig_instance, node_ref=e.args[0])
return [], []

for prop, value in override.items():
if prop == "guidPath":
Expand Down
1 change: 1 addition & 0 deletions src/converter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def has_rounded_corners(fig: dict) -> bool:
"SYM001": "references an invalid symbol. It will be converted to an empty placeholder group",
"SYM002": "overrides unsupported properties: {props}. The override will be ignored",
"SYM003": "overrides unsupported properties: {props}. The instance will be detached",
"SYM004": "contains an override of an unknown node {node_ref}. The override will be ignored",
"ART001": "has at least one corner radius which is not supported by sketch artboards. The corner radius will be ignored",
"ART002": "is being converted to an artboard. However, artboard rotations are not supported. Rotation will be ignored",
"ART003": "has a style that is not supported by sketch artboards. It will add a background rectangle to the artboard with the frame style",
Expand Down

0 comments on commit b488b46

Please sign in to comment.