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

AttributeError: 'SphinxRenderer' object has no attribute 'doc_env' when field description contains an invalid link #50

Open
duncandewhurst opened this issue Jul 3, 2023 · 1 comment

Comments

@duncandewhurst
Copy link

duncandewhurst commented Jul 3, 2023

Can we implement a more helpful error message or warning?

Minimal schema to reproduce:

{
  "properties": {
    "a": {
      "description": "[A bad link](notauri)."
    }
  }
}

Full traceback:

# Sphinx version: 5.3.0
# Python version: 3.11.0 (CPython)
# Docutils version: 0.17.1 release
# Jinja2 version: 3.1.2
# Last messages:
#   reading sources... [ 12%] about/governance
#   reading sources... [ 16%] about/index
#   reading sources... [ 20%] about/license
#   reading sources... [ 24%] data_model/codelists
#   reading sources... [ 28%] data_model/exposure
#   reading sources... [ 32%] data_model/general
#   reading sources... [ 36%] data_model/hazard
#   reading sources... [ 40%] data_model/index
#   reading sources... [ 44%] data_model/loss
#   reading sources... [ 48%] data_model/schema
# Loaded extensions:
#   sphinx.ext.mathjax (5.3.0) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/ext/mathjax.py
#   sphinxcontrib.applehelp (1.0.2) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/applehelp/__init__.py
#   sphinxcontrib.devhelp (1.0.2) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/devhelp/__init__.py
#   sphinxcontrib.htmlhelp (2.0.0) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/htmlhelp/__init__.py
#   sphinxcontrib.serializinghtml (1.1.5) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/serializinghtml/__init__.py
#   sphinxcontrib.qthelp (1.0.3) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/qthelp/__init__.py
#   alabaster (0.7.12) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/alabaster/__init__.py
#   myst_parser (0.18.1) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/__init__.py
#   sphinx_design (0.3.0) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx_design/__init__.py
#   sphinxcontrib.mermaid (5.3.0) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/mermaid.py
#   sphinxcontrib.opendataservices (unknown version) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/opendataservices.py
#   sphinxcontrib.jsonschema (unknown version) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/jsonschema.py
#   sphinx_rtd_theme (unknown version) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx_rtd_theme/__init__.py
#   sphinx.ext.todo (5.3.0) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/ext/todo.py
#   sphinx.ext.autodoc.preserve_defaults (5.3.0) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/ext/autodoc/preserve_defaults.py
#   sphinx.ext.autodoc.type_comment (5.3.0) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/ext/autodoc/type_comment.py
#   sphinx.ext.autodoc.typehints (5.3.0) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/ext/autodoc/typehints.py
#   sphinx.ext.autodoc (5.3.0) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/ext/autodoc/__init__.py
#   sphinx_togglebutton (0.3.2) from /home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx_togglebutton/__init__.py
Traceback (most recent call last):
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/cmd/build.py", line 281, in build_main
    app.build(args.force_all, args.filenames)
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/application.py", line 347, in build
    self.builder.build_update()
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 310, in build_update
    self.build(to_build,
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 326, in build
    updated_docnames = set(self.read())
                           ^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 433, in read
    self._read_serial(docnames)
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 454, in _read_serial
    self.read_doc(docname)
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 510, in read_doc
    publisher.publish()
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/docutils/core.py", line 217, in publish
    self.document = self.reader.read(self.source, self.parser,
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinx/io.py", line 104, in read
    self.parse()
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/docutils/readers/__init__.py", line 78, in parse
    self.parser.parse(self.input, document)
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/parsers/sphinx_.py", line 69, in parse
    parser.render(inputstring)
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/markdown_it/main.py", line 267, in render
    return self.renderer.render(self.parse(src, env), self.options, env)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/base.py", line 231, in render
    self._render_tokens(list(tokens))
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/base.py", line 210, in _render_tokens
    self.rules[f"render_{child.type}"](child)
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/base.py", line 603, in render_fence
    return self.render_directive(token)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/base.py", line 1239, in render_directive
    nodes_list = self.run_directive(name, arguments, content, position)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/base.py", line 1323, in run_directive
    result = directive_instance.run()
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/jsonschema.py", line 102, in run
    return self.make_nodes(schema)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/jsonschema.py", line 105, in make_nodes
    table = self.table(schema)
            ^^^^^^^^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/jsonschema.py", line 147, in table
    self.row(prop, tbody)
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/jsonschema.py", line 169, in row
    cell = self.cell(prop.description or '', morecols=3)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/jsonschema.py", line 203, in cell
    for child in to_docutils(text).children[:]:
                 ^^^^^^^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/sphinxcontrib/jsonschema.py", line 34, in to_docutils
    return parser.render(text)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/markdown_it/main.py", line 267, in render
    return self.renderer.render(self.parse(src, env), self.options, env)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/base.py", line 231, in render
    self._render_tokens(list(tokens))
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/base.py", line 210, in _render_tokens
    self.rules[f"render_{child.type}"](child)
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/base.py", line 445, in render_paragraph
    self.render_children(token)
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/base.py", line 359, in render_children
    self.rules[f"render_{child.type}"](child)
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/base.py", line 448, in render_inline
    self.render_children(token)
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/base.py", line 359, in render_children
    self.rules[f"render_{child.type}"](child)
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/base.py", line 709, in render_link
    return self.render_internal_link(token)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/sphinx_.py", line 104, in render_internal_link
    if self.doc_env.srcdir  # not set in some test situations
       ^^^^^^^^^^^^
  File "/home/ddewhurst/.pyenv/versions/3.11.0/envs/rdl-standard/lib/python3.11/site-packages/myst_parser/mdit_to_docutils/base.py", line 124, in __getattr__
    raise AttributeError(
AttributeError: 'SphinxRenderer' object has no attribute 'doc_env'
@odscjames
Copy link

Should be fixed by #53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants