diff --git a/py/show_text.py b/py/show_text.py index f0fb564..5a013a5 100644 --- a/py/show_text.py +++ b/py/show_text.py @@ -19,12 +19,24 @@ class ShowText: CATEGORY = "utils" - def notify(self, text, unique_id = None, extra_pnginfo=None): - if unique_id and extra_pnginfo and "workflow" in extra_pnginfo[0]: - workflow = extra_pnginfo[0]["workflow"] - node = next((x for x in workflow["nodes"] if str(x["id"]) == unique_id[0]), None) - if node: - node["widgets_values"] = [text] + def notify(self, text, unique_id=None, extra_pnginfo=None): + if unique_id is not None and extra_pnginfo is not None: + if not isinstance(extra_pnginfo, list): + print("Error: extra_pnginfo is not a list") + elif ( + not isinstance(extra_pnginfo[0], dict) + or "workflow" not in extra_pnginfo[0] + ): + print("Error: extra_pnginfo[0] is not a dict or missing 'workflow' key") + else: + workflow = extra_pnginfo[0]["workflow"] + node = next( + (x for x in workflow["nodes"] if str(x["id"]) == str(unique_id[0])), + None, + ) + if node: + node["widgets_values"] = [text] + return {"ui": {"text": text}, "result": (text,)}