Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

KeyError: 'id' processing TypeDoc #154

Open
tavianator opened this issue Sep 14, 2020 · 10 comments
Open

KeyError: 'id' processing TypeDoc #154

tavianator opened this issue Sep 14, 2020 · 10 comments

Comments

@tavianator
Copy link
Contributor

Just tried out sphinx-js 3.1 on https://github.com/microsoft/bistring. I'm getting the following error:

Handler <function analyze at 0x7f6538653550> for event 'builder-inited' threw an exception (exception: 'id')

I patched sphinx up a bit to get this trace:

Traceback (most recent call last):
  File "/home/tavianator/.local/share/virtualenvs/docs-BrgkGiab/lib/python3.8/site-packages/sphinx/events.py", line 110, in emit
    results.append(listener.handler(self.app, *args))
  File "/home/tavianator/.local/share/virtualenvs/docs-BrgkGiab/lib/python3.8/site-packages/sphinx_js/__init__.py", line 60, in analyze
    app._sphinxjs_analyzer = analyzer.from_disk(abs_source_paths,
  File "/home/tavianator/.local/share/virtualenvs/docs-BrgkGiab/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 40, in from_disk
    return cls(json, base_dir)
  File "/home/tavianator/.local/share/virtualenvs/docs-BrgkGiab/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 29, in __init__
    ir_objects = self._convert_all_nodes(json)
  File "/home/tavianator/.local/share/virtualenvs/docs-BrgkGiab/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 113, in _convert_all_nodes
    converted, more_todo = self._convert_node(todo.pop())
  File "/home/tavianator/.local/share/virtualenvs/docs-BrgkGiab/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 160, in _convert_node
    interfaces=self._related_types(node, kind='implementedTypes'),
  File "/home/tavianator/.local/share/virtualenvs/docs-BrgkGiab/lib/python3.8/site-packages/sphinx_js/typedoc.py", line 227, in _related_types
    pathname = Pathname(make_path_segments(self._index[type['id']],
KeyError: 'id'

Which points here.

The variable type looks like this:

{'type': 'reference', 'typeArguments': [{'type': 'reference', 'name': 'String'}], 'name': 'Iterable'}

So I expect the relevant code is this line.

@erikrose
Copy link
Contributor

erikrose commented Sep 14, 2020

Just off the top of my head, I wonder if we're hitting one of the cases I lopped off index_by_id() in 3d24151. I took them off because they either didn't make sense or I couldn't get the branches to be taken in any of the TS code I had to hand.

Edit: Nope, I don't think that's it at all. The class node, it seems, just lacks an id key.

@erikrose
Copy link
Contributor

erikrose commented Sep 14, 2020

If one of us can get it reduced, we can doubtless find a fix. I won't have time until at least next week.

@tavianator
Copy link
Contributor Author

Looks like this is enough to reproduce it:

diff --git a/tests/test_build_ts/source/class.ts b/tests/test_build_ts/source/class.ts
index f700886..b5fe2cc 100644
--- a/tests/test_build_ts/source/class.ts
+++ b/tests/test_build_ts/source/class.ts
@@ -53,3 +53,9 @@ interface OptionalThings {
   foop?(): void;
   boop?: boolean;
 }
+
+class Foo implements Iterable<string> {
+    [Symbol.iterator](): IterableIterator<string> {
+        return ""[Symbol.iterator]();
+    }
+}

Likewise I don't think I'llt have time to try to find a fix soon.

@erikrose
Copy link
Contributor

Got a couple failing test cases written. The root of the problem is that there's no good way to represent intrinsics—in your case, interfaces made solely out of intrinsics—in the IR, because the field for Class.interfaces is a Pathname. I'll have to change that.

@erikrose
Copy link
Contributor

erikrose commented Dec 9, 2020

More correctly, there's no way to represent types that cannot be expressed solely by a Pathname, like types that are built in or types that are parametrized (by <> or key of or whatever).

@ceelian
Copy link

ceelian commented Mar 16, 2021

Got the same error, is there a workaround to it in the meantime?

@erikrose
Copy link
Contributor

If TS will let you break your type off and give it a name, like someType = Iterable<string> and then reference it where you need it like class Foo implements someType, you might be able to dodge the error.

@ceelian
Copy link

ceelian commented Mar 16, 2021

@erikrose thank you for the suggested workaround. How can I find where in the TS project the issue occurs? Because typedoc alone runs without errors.

@erikrose
Copy link
Contributor

The problem is, as I explained in more depth above, a choice I made in our ir.py file. We'll need to fix it there. (Patches welcome; I don't know when I'll get to it.)

acivgin1 added a commit to acivgin1/sphinx-js that referenced this issue Feb 3, 2022
@bruce-wayne99
Copy link

Hello @erikrose just wanted to know if this issue is currently looked into. I am facing the same error as well.

hoodmane added a commit to hoodmane/sphinx-js that referenced this issue May 6, 2024
)

It didn't work correctly before because the description list label does not
render rst.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants