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

Anonymous avatarAnonymous 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 (1)

  1. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.