Handle hyprctl returning invalid json

This commit is contained in:
ItsDrike 2023-01-29 17:27:39 +01:00
parent 745e6838ec
commit d918406072
No known key found for this signature in database
GPG key ID: B014E761034AF742

View file

@ -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()
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()