From 730f95b1615ca0651464432ce511362f5a774816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E4=BC=9F?= Date: Thu, 14 Mar 2024 14:01:34 +0800 Subject: [PATCH] fix: Fix a bug in notify, line is "if unique_id and extra_pnginfo and workflow in extra_pnginfo[0]", Error: TypeError: argument of type NoneType is not iterable --- py/show_text.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) 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,)}