From be4783109c862f3251802c17bb204eed3166588a Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Sat, 6 Aug 2016 22:01:56 +0100 Subject: Fix out of index error in handleError In the latex parser when includes are processed, the text of the included file is directly included into the parse stream. This caused problems when there was an error in the included file (and the included file was longer than the original file) as the error would be reported at this position. The error handling tries to display the line and position where the error occured. It works by including a copy of the input and finding the place in the input when given the position of the error. In the previously described scenario, the input file would be the original source file but the error position would be the position of the error in the included file. The fix is to not try to show the exact line when it would cause an out-of-bounds error. --- src/Text/Pandoc/Error.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Error.hs b/src/Text/Pandoc/Error.hs index 792098b35..292396aee 100644 --- a/src/Text/Pandoc/Error.hs +++ b/src/Text/Pandoc/Error.hs @@ -62,8 +62,12 @@ handleError (Left err) = let errPos = errorPos err' errLine = sourceLine errPos errColumn = sourceColumn errPos - theline = (lines input ++ [""]) !! (errLine - 1) - in error $ "\nError at " ++ show err' ++ "\n" ++ - theline ++ "\n" ++ replicate (errColumn - 1) ' ' ++ - "^" + ls = lines input ++ [""] + errorInFile = if length ls > errLine - 1 + then concat ["\n", (ls !! (errLine - 1)) + ,"\n", replicate (errColumn - 1) ' ' + ,"^"] + else "" + in error $ "\nError at " ++ show err' + ++ errorInFile -- cgit v1.2.3