Skip to content

not enough arguments for format string when using -W #4070

Closed

Description

@anntzer

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

  1. added a commit that references this issue on Sep 24, 2017
    a455ffc
  2. added this to the 1.6.4 milestone on Sep 24, 2017
  3. tk0miya commented on Sep 24, 2017

    @tk0miya
    Member

    Thank you for reporting.
    Fixed at a455ffc

  4. dopplershift commented on Oct 3, 2017

    @dopplershift

    With 1.6.4 and the fix for this issue, I'm now getting this message instead:

    TypeError: not all arguments converted during string formatting
    

    Rolling back to 1.6.3 fixes it.

  5. added a commit that references this issue on Oct 4, 2017
    50640b7
  6. tk0miya commented on Oct 4, 2017

    @tk0miya
    Member

    Fixed again

  7. nikokio commented on Oct 23, 2017

    @nikokio

    Hello tk0miya,

    In which release will this new fix will be available ? 1.6.5 ?

    Thanks

  8. thijstriemstra commented on Oct 23, 2017

    @thijstriemstra
    Contributor

    Also ran into this issue with Sphinx 1.6.4 on readthedocs.io.

    In which release will this new fix will be available ? 1.6.5 ?

    The changelog puts this fix in 1.6.5.

  9. tk0miya commented on Oct 23, 2017

    @tk0miya
    Member

    Yes, it is fixed again in 1.6.5. Please try it.

  10. thijstriemstra commented on Oct 23, 2017

    @thijstriemstra
    Contributor

    Yes, it is fixed again in 1.6.5. Please try it.

    Works fine with 1.6.5, thanks.

  11. locked as resolved and limited conversation to collaborators on Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions