From d918406072cf20e7915f62a0f4ff22647aca26a5 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sun, 29 Jan 2023 17:27:39 +0100 Subject: [PATCH] Handle hyprctl returning invalid json --- home/.config/eww/scripts/workspaces.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/home/.config/eww/scripts/workspaces.py b/home/.config/eww/scripts/workspaces.py index 6d30fba..3b5e1de 100755 --- a/home/.config/eww/scripts/workspaces.py +++ b/home/.config/eww/scripts/workspaces.py @@ -106,7 +106,15 @@ def get_workspaces() -> list[OutputWorkspaceInfo]: """Obtain workspaces from hyprctl, sort them and add format_name arg.""" proc = subprocess.run(["hyprctl", "workspaces", "-j"], stdout=subprocess.PIPE) proc.check_returncode() - workspaces: list[WorkspaceInfo] = json.loads(proc.stdout) + try: + workspaces: list[WorkspaceInfo] = json.loads(proc.stdout) + except json.JSONDecodeError: + sys.stderr.writelines([ + "Error decoding json response from hyprctl, returning empty workspaces", + f"Actual captured output from hyprctl: {proc.stdout!r}" + ]) + sys.stderr.flush() + workspaces = [] proc = subprocess.run(["hyprctl", "monitors", "-j"], stdout=subprocess.PIPE) proc.check_returncode()