From a012f65542eb09664eec7f85b0c79cdca7e37588 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Tue, 7 May 2024 17:11:03 +0200 Subject: [PATCH] If we fail to find the object given by path, catch the error (#162) This corresponds to some slightly weird code paths in convertReferenceToXRef. Ideally we'd fix them but I don't know how. --- sphinx_js/js/convertType.ts | 2 ++ sphinx_js/renderers.py | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/sphinx_js/js/convertType.ts b/sphinx_js/js/convertType.ts index f86c8569..2cfd7516 100644 --- a/sphinx_js/js/convertType.ts +++ b/sphinx_js/js/convertType.ts @@ -287,6 +287,8 @@ class TypeConverter implements TypeVisitor { }; return this.addTypeArguments(type, [xref]); } else { + // TODO: I'm not sure that it's right to generate an internal xref here. + // We need better test coverage for this code path. const xref: TypeXRefInternal = { name: type.name, path, diff --git a/sphinx_js/renderers.py b/sphinx_js/renderers.py index 746d364b..e8de493d 100644 --- a/sphinx_js/renderers.py +++ b/sphinx_js/renderers.py @@ -454,11 +454,18 @@ def strs() -> Iterator[str]: def render_xref(self, s: TypeXRef, escape: bool = False) -> str: obj = None if isinstance(s, TypeXRefInternal): - obj = self.lookup_object(s.path) - # Stick the kind on the xref so that the formatter will know what - # xref role to emit. I'm not sure how to compute this earlier. It's - # convenient to do it here. - s.kind = type(obj).__name__.lower() + try: + obj = self.lookup_object(s.path) + # Stick the kind on the xref so that the formatter will know what + # xref role to emit. I'm not sure how to compute this earlier. It's + # convenient to do it here. + s.kind = type(obj).__name__.lower() + except SphinxError: + # This sometimes happens on the code path in + # convertReferenceToXRef when we generate an xref internal from + # a symbolId. That code path is probably entirely wrong. + # TODO: fix and add test coverage. + pass result = self._type_xref_formatter(s) if escape: result = rst.escape(result)