diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2016-08-06 22:01:56 +0100 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2016-08-06 22:06:37 +0100 |
commit | be4783109c862f3251802c17bb204eed3166588a (patch) | |
tree | 5dc21b8b3f010d24292c596ec9a1b5cb469cbb33 /src/Text/Pandoc/Error.hs | |
parent | cde1f008134c854e241e3ff9c4d352a84e64356e (diff) |
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.
Diffstat (limited to 'src/Text/Pandoc/Error.hs')
-rw-r--r-- | src/Text/Pandoc/Error.hs | 12 |
1 files changed, 8 insertions, 4 deletions
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 |