From e565ad5f55dde34dec425f95a109ee60fb79c3f7 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 21 Jul 2024 20:36:50 +0000 Subject: [PATCH] better errors through broker --- copyparty/broker_util.py | 6 +++--- copyparty/httpcli.py | 7 ++----- copyparty/util.py | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/copyparty/broker_util.py b/copyparty/broker_util.py index 105ac535..22c419f2 100644 --- a/copyparty/broker_util.py +++ b/copyparty/broker_util.py @@ -28,7 +28,7 @@ class ExceptionalQueue(Queue, object): if rv[1] == "pebkac": raise Pebkac(*rv[2:]) else: - raise Exception(rv[2]) + raise rv[2] return rv @@ -65,8 +65,8 @@ def try_exec(want_retval: Union[bool, int], func: Any, *args: list[Any]) -> Any: return ["exception", "pebkac", ex.code, str(ex)] - except: + except Exception as ex: if not want_retval: raise - return ["exception", "stack", traceback.format_exc()] + return ["exception", "stack", ex] diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 30df2ddf..decaae7e 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -646,11 +646,8 @@ class HttpCli(object): if not self._check_nonfatal(pex, post): self.keepalive = False - if pex is ex: - em = msg = str(ex) - else: - em = repr(ex) - msg = min_ex() + em = str(ex) + msg = em if pex is ex else min_ex() if pex.code != 404 or self.do_log: self.log( diff --git a/copyparty/util.py b/copyparty/util.py index a117755a..74e34f0c 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -1377,7 +1377,7 @@ def vol_san(vols: list["VFS"], txt: bytes) -> bytes: def min_ex(max_lines: int = 8, reverse: bool = False) -> str: et, ev, tb = sys.exc_info() stb = traceback.extract_tb(tb) if tb else traceback.extract_stack()[:-1] - fmt = "%s @ %d <%s>: %s" + fmt = "%s:%d <%s>: %s" ex = [fmt % (fp.split(os.sep)[-1], ln, fun, txt) for fp, ln, fun, txt in stb] if et or ev or tb: ex.append("[%s] %s" % (et.__name__ if et else "(anonymous)", ev))