From e7b433ee543b20ca848f23013590e43cf5d8baf0 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Wed, 12 Jun 2024 01:40:38 +0200 Subject: [PATCH] Throw more informative error classes from perf. --- pdm/perf.py | 7 +++++++ pdm/srv.py | 11 ++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pdm/perf.py b/pdm/perf.py index 7c93c85..7c0d561 100644 --- a/pdm/perf.py +++ b/pdm/perf.py @@ -51,6 +51,13 @@ __all__ = ["attrinfo", "simpleattr", "valueattr", "eventobj", "staticdir", "event", "procevent", "startevent", "finishevent"] +class error(Exception): + pass +class nosuchname(LookupError, error): + pass +class nosuchproto(error): + pass + class attrinfo(object): """The return value of the `attrinfo' method on `attr' objects as described in L{pdm.srv.perf}. diff --git a/pdm/srv.py b/pdm/srv.py index 80f9a26..2ddb9e7 100644 --- a/pdm/srv.py +++ b/pdm/srv.py @@ -10,6 +10,7 @@ which describes the functioning of the REPL and PERF protocols. import os, sys, socket, threading, grp, select import types, pprint, traceback import pickle, struct +from . import perf as mperf __all__ = ["repl", "perf", "listener", "unixlistener", "tcplistener", "listen"] @@ -197,7 +198,7 @@ class perf(object): def bindob(self, id, ob): if not hasattr(ob, "pdm_protocols"): - raise ValueError("Object does not support PDM introspection") + raise mperf.nosuchname("Object does not support PDM introspection") try: proto = ob.pdm_protocols() except Exception as exc: @@ -208,12 +209,12 @@ class perf(object): def bind(self, id, module, obnm): resmod = sys.modules.get(module) if resmod is None: - self.send("-", ImportError("No such module: %s" % module)) + self.send("-", mperf.nosuchname("No such module: %s" % module)) return try: ob = getattr(resmod, obnm) except AttributeError: - self.send("-", AttributeError("No such object: %s" % obnm)) + self.send("-", mperf.nosuchname("No such object: %s" % obnm)) return try: proto = self.bindob(id, ob) @@ -229,7 +230,7 @@ class perf(object): return None ob, protos = ob if proto not in protos: - self.send("-", ValueError("Object does not support that protocol")) + self.send("-", mperf.nosuchproto("Object does not support that protocol: " + proto)) return None return ob @@ -240,7 +241,7 @@ class perf(object): try: ob = src.lookup(obnm) except KeyError as exc: - self.send("-", exc) + self.send("-", mperf.nosuchname(obnm)) return try: proto = self.bindob(tgtid, ob) -- 2.11.0