git.iko.soy/typeable/pandoc
on master help sign in
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.

commitbe4783109c862f3251802c17bb204eed3166588a authorMatthew Pickering <matthewtpickering@gmail.com> dateSat 6 Aug 2016, 22:01 (10 years ago) parentcde1f00
1 file changed+8−4
src/Text/Pandoc/Error.hs+8−4
src/Text/Pandoc/Error.hs+8−4
@@ -62,8 +62,12 @@ handleError (Left err) =
6262 let errPos = errorPos err'
6363 errLine = sourceLine errPos
6464 errColumn = sourceColumn errPos
65− theline = (lines input ++ [""]) !! (errLine - 1)
66− in error $ "\nError at " ++ show err' ++ "\n" ++
67− theline ++ "\n" ++ replicate (errColumn - 1) ' ' ++
68− "^"
65+ ls = lines input ++ [""]
66+ errorInFile = if length ls > errLine - 1
67+ then concat ["\n", (ls !! (errLine - 1))
68+ ,"\n", replicate (errColumn - 1) ' '
69+ ,"^"]
70+ else ""
71+ in error $ "\nError at " ++ show err'
72+ ++ errorInFile
6973