Skip to content

Allow a CLI that does not handle Exceptions. #10670

@Jacob-Stevens-Haas

Description

@Jacob-Stevens-Haas

Is your feature request related to a problem? Please describe.
I would like to use my IDE's debugger to find out where SphinxErrors are coming from. In particular, I got the error toctree contains reference to nonexisting document when I didn't delete any documents from my repo. I'm not really familiar with PdB, so I tried putting an entry in my IDE's debugging config to run sphinx (This is VSCode, launch.json)

        {
            "name": "Documentation",
            "type": "python",
            "request": "launch",
            "module": "sphinx.cmd.build",
            "console": "integratedTerminal",
            "justMyCode": false,
            "args": [
                "-TEW",
                "-b",
                "html",
                "-d",
                " docs/_build/doctrees",
                "docs",
                "docs/_build/html"
            ]
        },

Unfortunately, all of the important work in the CLI gets passed through a try...except, and errors are sent to sphinx.cmd.build.handle_exception(), which just prints the error. So my debugger only catches the SystemExit exception. I can't get back into the call stack that generated the original exception and inspect variables.

Describe the solution you'd like
Move graceful exception handling to sphinx.__main__ so that people can debug sphinx.cmd.build with their IDE.

Describe alternatives you've considered

  • This is also feels like slightly an issue with the -W flag, which doesn't actually raise an exception to the level of the python interpreter: it prints the exception, then sends sys.exit(2). That makes sense, and seems like the current behavior is necessary for --keep-going to be feasible. Perhaps sphinx.cmd.build.__main__() could handle the parsing, check for -W and --keep-going, and take over the call to handle_exception() from build_main(). That way, it could conditionally re-raise the exception.
  • I can set my debugger to catch all exceptions, not just unhandled ones, but then I catch a variety of spurious exceptions.
  • I can add a breakpoint in sphinx.cmd.build.handle_exceptions(), but I don't know if there's a way to pass the local exception variable to my IDE's debugger and view that stack?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions