Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError in dataclasses.py with example project #25

Open
segfaultxavi opened this issue Feb 5, 2025 · 2 comments
Open

KeyError in dataclasses.py with example project #25

segfaultxavi opened this issue Feb 5, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@segfaultxavi
Copy link

I am sure I am doing something wrong. TypeScript is not my thing.
But this example at least shows that something is not shutting down gracefully.

bug1.zip

$ mkdocs build
INFO    -  DeprecationWarning: Setting a fallback anchor function is deprecated and will be removed in a future release.
             File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings/plugin.py", line 190, in on_config
               autorefs.get_fallback_anchor = self.handlers.get_anchors
             File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocs_autorefs/plugin.py", line 130, in get_fallback_anchor
               warn(
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: /home/xartigas/repos/symbol/k/docs/site
INFO    -  griffe_typedoc: json generated at /tmp/tmp6vanqdqp
ERROR   -  Error reading page 'index.md': 1
Traceback (most recent call last):
  File "/home/xartigas/.local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocs/__main__.py", line 288, in build_command
    build.build(cfg, dirty=not clean)
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocs/commands/build.py", line 310, in build
    _populate_page(file.page, config, files, dirty)
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocs/commands/build.py", line 167, in _populate_page
    page.render(config, files)
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocs/structure/pages.py", line 285, in render
    self.content = md.convert(self.markdown)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/markdown/core.py", line 357, in convert
    root = self.parser.parseDocument(self.lines).getroot()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/markdown/blockparser.py", line 117, in parseDocument
    self.parseChunk(self.root, '\n'.join(lines))
  File "/home/xartigas/.local/lib/python3.12/site-packages/markdown/blockparser.py", line 136, in parseChunk
    self.parseBlocks(parent, text.split('\n\n'))
  File "/home/xartigas/.local/lib/python3.12/site-packages/markdown/blockparser.py", line 158, in parseBlocks
    if processor.run(parent, blocks) is not False:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings/extension.py", line 130, in run
    html, handler, data = self._process_block(identifier, block, heading_level)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings/extension.py", line 230, in _process_block
    rendered = handler.render(data, options)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/handler.py", line 187, in render
    return template.render(
           ^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/jinja2/environment.py", line 1295, in render
    self.environment.handle_exception()
  File "/home/xartigas/.local/lib/python3.12/site-packages/jinja2/environment.py", line 942, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/dispatch.html.jinja", line 1, in top-level template code
    {% extends "_base/dispatch.html.jinja" %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/_base/dispatch.html.jinja", line 32, in top-level template code
    {% include "class.html.jinja" with context %}
^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/class.html.jinja", line 1, in top-level template code
    {% extends "_base/class.html.jinja" %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/_base/class.html.jinja", line 52, in top-level template code
    {% block contents scoped %}
^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/_base/class.html.jinja", line 58, in block 'contents'
    {% block children scoped %}
^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/_base/class.html.jinja", line 61, in block 'children'
    {% include "children.html.jinja" with context %}
^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/children.html.jinja", line 1, in top-level template code
    {% extends "_base/children.html.jinja" %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/_base/children.html.jinja", line 18, in top-level template code
    {% include "dispatch.html.jinja" with context %}
^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/dispatch.html.jinja", line 1, in top-level template code
    {% extends "_base/dispatch.html.jinja" %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/_base/dispatch.html.jinja", line 48, in top-level template code
    {% include "method.html.jinja" with context %}
^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/method.html.jinja", line 1, in top-level template code
    {% extends "_base/method.html.jinja" %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/_base/method.html.jinja", line 52, in top-level template code
    {% block contents scoped %}
^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/_base/method.html.jinja", line 58, in block 'contents'
    {% block signatures scoped %}
^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/_base/method.html.jinja", line 60, in block 'signatures'
    {% include "dispatch.html.jinja" with context %}
^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/dispatch.html.jinja", line 1, in top-level template code
    {% extends "_base/dispatch.html.jinja" %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/_base/dispatch.html.jinja", line 52, in top-level template code
    {% include "call_signature.html.jinja" with context %}
^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/call_signature.html.jinja", line 1, in top-level template code
    {% extends "_base/call_signature.html.jinja" %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/mkdocstrings_handlers/typescript/templates/material/_base/call_signature.html.jinja", line 7, in top-level template code
    {{ call_signature.source_contents }}
^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/jinja2/environment.py", line 490, in getattr
    return getattr(obj, attribute)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/griffe_typedoc/dataclasses.py", line 337, in source_contents
    return "\n".join(source.contents for source in self.sources).rstrip().removesuffix("{")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/griffe_typedoc/dataclasses.py", line 337, in <genexpr>
    return "\n".join(source.contents for source in self.sources).rstrip().removesuffix("{")
                     ^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/griffe_typedoc/dataclasses.py", line 217, in contents
    with Path(self.filepath).open() as file:
              ^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/griffe_typedoc/dataclasses.py", line 213, in filepath
    return self.parent.root.files.filepath(self.parent.root_module.id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xartigas/.local/lib/python3.12/site-packages/griffe_typedoc/dataclasses.py", line 152, in filepath
    return self.entries[self.reverse_reflections[reflection_id]]
                        ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 1
@segfaultxavi
Copy link
Author

I have added a second source TS file and the problem went away. Maybe the problem was a single source TS file?

@pawamoy
Copy link
Member

pawamoy commented Feb 5, 2025

Not sure, I'll check your ZIP archive (thank you so much for providing it 🙏)!

@pawamoy pawamoy added the bug Something isn't working label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants