From 4aa84f40060884311324d3dd0a81ec22fdd9329f Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 21 Oct 2017 21:51:16 -0700 Subject: In rendering PandocParsecError, only print input at error location... if the source name is `source` (i.e., the top level). Otherwise results will be misleading, since what readM does is to look up the source position of the error in the *original* input, which may not match the input used by parseFromString or in parsing from an included file. Closes #3865. Not a great fix, maybe there's something better that could be done, but this should at least avoid misleading messages. --- src/Text/Pandoc/Error.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Error.hs b/src/Text/Pandoc/Error.hs index 2bd8bef0a..a05cdfe43 100644 --- a/src/Text/Pandoc/Error.hs +++ b/src/Text/Pandoc/Error.hs @@ -90,7 +90,12 @@ handleError (Left e) = ,"\n", replicate (errColumn - 1) ' ' ,"^"] else "" - in err 65 $ "\nError at " ++ show err' ++ errorInFile + in err 65 $ "\nError at " ++ show err' ++ + -- if error comes from a chunk or included file, + -- then we won't get the right text this way: + if sourceName errPos == "source" + then errorInFile + else "" PandocMakePDFError s -> err 65 s PandocOptionError s -> err 2 s PandocSyntaxMapError s -> err 67 s -- cgit v1.2.3