Repository navigation
Description
Subject: When a build raises a warning that contains "%s" and the -W switch is on, sphinx-build crashes with "not enough arguments for format string"
Problem
See subject.
Procedure to reproduce the problem
pkg/__init__.py
raise RuntimeError("oops %s")
Create a doc folder with
$ sphinx-apidoc -o doc -F pkg
and build the docs with make SPHINXOPTS=-W html (and with pkg in your path).
Error logs / results
python -msphinx -b html -d _build/doctrees -W . _build/html
Running Sphinx v1.6.3
loading translations [en]... done
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
reading sources... [100%] pkg
Exception occurred:
File "/usr/lib/python3.6/site-packages/sphinx/util/logging.py", line 338, in filter
raise SphinxWarning(record.msg % record.args)
TypeError: not enough arguments for format string
The full traceback has been saved in /tmp/sphinx-err-_a2gske8.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** [Makefile:55: html] Error 1
Expected results
Exit with a normal error (similar to when there is no %s in the warning), such that the actual interesting error message is displayed.
python -msphinx -b html -d _build/doctrees -W . _build/html
Running Sphinx v1.6.3
loading translations [en]... done
loading pickled environment... not yet created
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 2 source files that are out of date
updating environment: 2 added, 0 changed, 0 removed
reading sources... [100%] pkg
Warning, treated as error:
/tmp/foo/doc/pkg.rst:7: (WARNING/2) autodoc: failed to import module 'pkg'; the following exception was raised:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/sphinx/ext/autodoc.py", line 657, in import_object
__import__(self.modname)
File "/tmp/foo/pkg/__init__.py", line 1, in <module>
raise RuntimeError("oops")
RuntimeError: oops
make: *** [Makefile:55: html] Error 1
This example is of course a bit contrieved (to keep it concise), but you can easily imagine other cases where the warning contains a %s.
The solution is probably to call log("%s", msg) instead of log(msg) at the right place (cf https://en.wikipedia.org/wiki/Uncontrolled_format_string).
Reproducible project / your project
- N/A
Environment info
- OS: Arch Linux
- Python version: 3.6
- Sphinx version: 1.6.3
Activity
Fix #4070: crashes when the warning message contains format strings
tk0miya commentedon Sep 24, 2017
Thank you for reporting.
Fixed at a455ffc
dopplershift commentedon Oct 3, 2017
With 1.6.4 and the fix for this issue, I'm now getting this message instead:
Rolling back to 1.6.3 fixes it.
Fix #4070, #4111: crashes when the warning message contains format st…
tk0miya commentedon Oct 4, 2017
Fixed again
nikokio commentedon Oct 23, 2017
Hello tk0miya,
In which release will this new fix will be available ? 1.6.5 ?
Thanks
thijstriemstra commentedon Oct 23, 2017
Also ran into this issue with Sphinx 1.6.4 on readthedocs.io.
The changelog puts this fix in 1.6.5.
tk0miya commentedon Oct 23, 2017
Yes, it is fixed again in 1.6.5. Please try it.
thijstriemstra commentedon Oct 23, 2017
Works fine with 1.6.5, thanks.