-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
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
-Wflag, which doesn't actually raise an exception to the level of the python interpreter: it prints the exception, then sendssys.exit(2). That makes sense, and seems like the current behavior is necessary for--keep-goingto be feasible. Perhapssphinx.cmd.build.__main__()could handle the parsing, check for-Wand--keep-going, and take over the call tohandle_exception()frombuild_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?