Fail the same way on JSON of an unexpected shape

json.loads succeeding does not mean the result is a list of objects with an
id. A dict, an entry without an id, or a scalar raised TypeError or KeyError,
which escaped unhandled and defeated the point of the change. Both cases now
raise DaemonError, and the original exception is chained so the cause is
visible.
This commit is contained in:
Maxim Shulga committed 2026-08-02 17:33:45 -07:00
1 parent b75863ba51
commit 2e18a774f2
2 files changed
+33 -2

No files matched your search

+11 -2
View File
@@ -281,9 +281,18 @@ class SeafileClient:
try:
libraries = json.loads(out.decode())
except (UnicodeDecodeError, ValueError) as err:
raise DaemonError(f"Cannot read the library list from seaf-cli: {err}")
raise DaemonError(
f"Cannot read the library list from seaf-cli: {err}"
) from err
return {lib["id"] for lib in libraries}
# Valid JSON is not necessarily the expected shape, and an unexpected
# one must fail the same way rather than as a bare TypeError.
try:
return {lib["id"] for lib in libraries}
except (KeyError, TypeError) as err:
raise DaemonError(
f"Unexpected library list from seaf-cli: {err}"
) from err
def configure(self, args: argparse.Namespace, check_for_daemon: bool = True):
need_restart = False