Skip to content

Cryptic error message from failing to parse invalid rst docstrings #302

Closed
@nialov

Description

@nialov

Problem

A cryptic error message is raised by process_docstring failing to parse a rst docstring within Python code.

sphinx.errors.ExtensionError: Handler <function process_docstring at 0x7efe073368b0> for event 'autodoc-process-docstring' threw an exception (exception: )

Example of invalid docstrings:

  @staticmethod
  def conditional_linemerge(
      first: LineString, second: LineString, tolerance: float, buffer_value: float
  ) -> Union[None, LineString]:
      """
      Conditionally merge two LineStrings (first and second).

      Merge occurs if:
          1. Their endpoints are within buffer_value of each other.
          2. Their total orientations are within tolerance (degrees) of each
             other.

      """

The issue is the indented part after the colon with the numbers.

What I expected

The issue of invalid rst is of course an user error and it is of course great that sphinx-autodoc-typehints finds these invalid portions but the error report should clarify where the error occurs and possibly why. Otherwise it is difficult for the user to understand what is wrong.

Further info

I managed to debug the issue myself by running sphinx-build with the verbose flags (-vvv). The issue is further exacerbated by the fact that the sphinx log can contain additional logging outputs between the exception reporting and the log that displays which part of the code sphinx is currently processing. See the log as a gist here: https://gist.github.com/nialov/e92dcf8aa43c9108b31c37df28725188. At the very start, the emitting event parts tell where the parsing is currently occurring. After it a number of irrelevant warnings are raised, which I have mostly deleted to keep the log cleaner, and then the exception is printed out. The exception itself contains no useful information, only that the function process_docstring failed somewhere in the documentation. The log without the verbosity flags -vvv is much more cryptic as only the end exception is outputted.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions