aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-11-29 15:59:10 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2018-11-29 15:59:10 -0800
commit747f079bad8c2b2db3e279daf4649659bd50625e (patch)
tree6bb3265cd07f6056e8a68acaf40eb4cf66d94182 /src
parentec07a5298c27ff6b6fb59cbc29aa91f0469650d5 (diff)
downloadpandoc-747f079bad8c2b2db3e279daf4649659bd50625e.tar.gz
Add PandocUTF8DecodingError constructor for PandocError.
[API change]
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Error.hs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Error.hs b/src/Text/Pandoc/Error.hs
index feb047f68..e4a5bb092 100644
--- a/src/Text/Pandoc/Error.hs
+++ b/src/Text/Pandoc/Error.hs
@@ -38,11 +38,13 @@ module Text.Pandoc.Error (
import Prelude
import Control.Exception (Exception)
import Data.Typeable (Typeable)
+import Data.Word (Word8)
import GHC.Generics (Generic)
import Network.HTTP.Client (HttpException)
import System.Exit (ExitCode (..), exitWith)
import System.IO (stderr)
import qualified Text.Pandoc.UTF8 as UTF8
+import Text.Printf (printf)
import Text.Parsec.Error
import Text.Parsec.Pos hiding (Line)
@@ -67,6 +69,7 @@ data PandocError = PandocIOError String IOError
| PandocAppError String
| PandocEpubSubdirectoryError String
| PandocMacroLoop String
+ | PandocUTF8DecodingError String Int Word8
deriving (Show, Typeable, Generic)
instance Exception PandocError
@@ -117,6 +120,10 @@ handleError (Left e) =
"EPUB subdirectory name '" ++ s ++ "' contains illegal characters"
PandocMacroLoop s -> err 91 $
"Loop encountered in expanding macro " ++ s
+ PandocUTF8DecodingError f offset w -> err 92 $
+ "UTF-8 decoding error in " ++ f ++ " at byte offset " ++ show offset ++
+ " (" ++ printf "%2x" w ++ ").\n" ++
+ "The input must be a UTF-8 encoded text."
err :: Int -> String -> IO a
err exitCode msg = do