Issue #675 resolved

Python exception when literalinclude lines that are beyond a file's bounds...

Anonymous created an issue

When you use a '.. literalinclude::' which specifies lines to be included, that are beyond the range of the actual file, a python 'IndexError: list index out of range' exception is thrown. Apparently, sphinx doesn't check to see that the requested lines are within the bounds of the file. Here's an example:

Assume 'foo.txt' only contains 3 lines. They could be anything. Here's the sphinx markup to include lines 10-20 (lines that don't exist):

{{{ .. literalinclude:: foo.txt :lines: 10-20 }}}

When we build, such as 'make html', Python throws an exception:

{{{ Exception occurred:
File "/usr/local/lib/python2.6/site-packages/Sphinx-1.0.7-py2.6.egg/sphinx/dirrctives/", line 155, in run
lines = [lines[i] for i in linelist]
IndexError: list index out of range
The full traceback has been saved in /tmp/sphinx-err-mm9Uje.log, if you want to eport the issue to the developers.
Please also report this if it was a user error, so that a better error message ccn be provided next time.
Either send bugs to the mailing list at,
or report them in the tracker at < Thanks! }}}

I discovered this today by accidently including the wrong file in one of my documentation projects, a file which wasn't long enough to include the requested lines.

Comments (3)

  1. Log in to comment