From 691ace354313d5eadb55131355022126b7aaf611 Mon Sep 17 00:00:00 2001 From: awsr <43862868+awsr@users.noreply.github.com> Date: Sun, 28 Dec 2025 02:25:43 -0800 Subject: [PATCH 1/5] Add warning messages --- modules/json_helpers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/json_helpers.py b/modules/json_helpers.py index e06c835f4..3c2facda0 100644 --- a/modules/json_helpers.py +++ b/modules/json_helpers.py @@ -59,11 +59,13 @@ def readfile(filename: str, silent: bool = False, lock: bool = False, *, as_type except Exception: locking_available = False if isinstance(data, list) and as_type == "dict": + log.warning(f"Read: Expected dictionary from '{filename}' but got list") data0 = data[0] if isinstance(data0, dict): return data0 return {} if isinstance(data, dict) and as_type == "list": + log.warning(f"Read: Expected list from '{filename}' but got dictionary") return [data] return data From 70081e0d7475b149bb9044f07d17bfa2f2a4a4b3 Mon Sep 17 00:00:00 2001 From: awsr <43862868+awsr@users.noreply.github.com> Date: Sun, 28 Dec 2025 02:38:17 -0800 Subject: [PATCH 2/5] Fix default value --- modules/json_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/json_helpers.py b/modules/json_helpers.py index 3c2facda0..5cb495437 100644 --- a/modules/json_helpers.py +++ b/modules/json_helpers.py @@ -19,7 +19,7 @@ def readfile(filename: str, silent: bool = False, lock: bool = False, *, as_type def readfile(filename: str, silent: bool = False, lock: bool = False) -> dict | list: ... def readfile(filename: str, silent: bool = False, lock: bool = False, *, as_type="") -> dict | list: global locking_available # pylint: disable=global-statement - data = {} + data = {} if as_type == "dict" else [] lock_file = None locked = False if lock and locking_available: From 66f55a7d7c10e2c31c868b9b2a95790732d6a18c Mon Sep 17 00:00:00 2001 From: awsr <43862868+awsr@users.noreply.github.com> Date: Sun, 28 Dec 2025 02:59:51 -0800 Subject: [PATCH 3/5] Better data handling --- modules/json_helpers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/json_helpers.py b/modules/json_helpers.py index 5cb495437..600f5fc8c 100644 --- a/modules/json_helpers.py +++ b/modules/json_helpers.py @@ -59,13 +59,15 @@ def readfile(filename: str, silent: bool = False, lock: bool = False, *, as_type except Exception: locking_available = False if isinstance(data, list) and as_type == "dict": - log.warning(f"Read: Expected dictionary from '{filename}' but got list") + if not data: + return {} data0 = data[0] if isinstance(data0, dict): return data0 return {} if isinstance(data, dict) and as_type == "list": - log.warning(f"Read: Expected list from '{filename}' but got dictionary") + if not data: + return [] return [data] return data From 89fd729d74069a3ea1aa51352e3c5c8191b6588d Mon Sep 17 00:00:00 2001 From: awsr <43862868+awsr@users.noreply.github.com> Date: Sun, 28 Dec 2025 03:02:39 -0800 Subject: [PATCH 4/5] Restore accidental deletion --- modules/json_helpers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/json_helpers.py b/modules/json_helpers.py index 600f5fc8c..16fe0a55a 100644 --- a/modules/json_helpers.py +++ b/modules/json_helpers.py @@ -59,6 +59,7 @@ def readfile(filename: str, silent: bool = False, lock: bool = False, *, as_type except Exception: locking_available = False if isinstance(data, list) and as_type == "dict": + log.warning(f"Read: Expected dictionary from '{filename}' but got list") if not data: return {} data0 = data[0] @@ -66,6 +67,7 @@ def readfile(filename: str, silent: bool = False, lock: bool = False, *, as_type return data0 return {} if isinstance(data, dict) and as_type == "list": + log.warning(f"Read: Expected list from '{filename}' but got dictionary") if not data: return [] return [data] From 7c01fd71de3d0368ecf316d40443a65924e79aa6 Mon Sep 17 00:00:00 2001 From: awsr <43862868+awsr@users.noreply.github.com> Date: Sun, 28 Dec 2025 03:10:22 -0800 Subject: [PATCH 5/5] Don't warn about file if not reading from a file Leave that up to the other log messages --- modules/json_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/json_helpers.py b/modules/json_helpers.py index 16fe0a55a..2615d1a03 100644 --- a/modules/json_helpers.py +++ b/modules/json_helpers.py @@ -59,17 +59,17 @@ def readfile(filename: str, silent: bool = False, lock: bool = False, *, as_type except Exception: locking_available = False if isinstance(data, list) and as_type == "dict": - log.warning(f"Read: Expected dictionary from '{filename}' but got list") if not data: return {} + log.warning(f"Read: Expected dictionary from '{filename}' but got list") data0 = data[0] if isinstance(data0, dict): return data0 return {} if isinstance(data, dict) and as_type == "list": - log.warning(f"Read: Expected list from '{filename}' but got dictionary") if not data: return [] + log.warning(f"Read: Expected list from '{filename}' but got dictionary") return [data] return data