From: Daniele Varrazzo Date: Tue, 24 Aug 2021 15:18:30 +0000 (+0200) Subject: More helpful error looking up for missing types in the registry X-Git-Tag: 3.0.beta1~50 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8798a5a1ef6cd17114dac62acaf88c3331bc081b;p=thirdparty%2Fpsycopg.git More helpful error looking up for missing types in the registry --- diff --git a/psycopg/psycopg/_typeinfo.py b/psycopg/psycopg/_typeinfo.py index 5fb73e07a..8fff12c16 100644 --- a/psycopg/psycopg/_typeinfo.py +++ b/psycopg/psycopg/_typeinfo.py @@ -288,15 +288,20 @@ class TypesRegistry: Raise KeyError if not found. """ - if isinstance(key, str): - if key.endswith("[]"): - key = key[:-2] - return self._by_name[key] - elif isinstance(key, int): - return self._by_oid[key] - else: - raise TypeError( - f"the key must be an oid or a name, got {type(key)}" + try: + if isinstance(key, str): + if key.endswith("[]"): + key = key[:-2] + return self._by_name[key] + elif isinstance(key, int): + return self._by_oid[key] + else: + raise TypeError( + f"the key must be an oid or a name, got {type(key)}" + ) + except KeyError: + raise KeyError( + f"couldn't find the type {key!r} in the types registry" ) def get(self, key: Union[str, int]) -> Optional[TypeInfo]: