@@ -38,11 +38,13 @@ module Text.Pandoc.Error (
38import Prelude
38import Prelude
39import Control.Exception (Exception)
39import Control.Exception (Exception)
40import Data.Typeable (Typeable)
40import Data.Typeable (Typeable)
41+import Data.Word (Word8)
41import GHC.Generics (Generic)
42import GHC.Generics (Generic)
42import Network.HTTP.Client (HttpException)
43import Network.HTTP.Client (HttpException)
43import System.Exit (ExitCode (..), exitWith)
44import System.Exit (ExitCode (..), exitWith)
44import System.IO (stderr)
45import System.IO (stderr)
45import qualified Text.Pandoc.UTF8 as UTF8
46import qualified Text.Pandoc.UTF8 as UTF8
47+import Text.Printf (printf)
46import Text.Parsec.Error
48import Text.Parsec.Error
47import Text.Parsec.Pos hiding (Line)
49import Text.Parsec.Pos hiding (Line)
@@ -67,6 +69,7 @@ data PandocError = PandocIOError String IOError
67 | PandocAppError String
69 | PandocAppError String
68 | PandocEpubSubdirectoryError String
70 | PandocEpubSubdirectoryError String
69 | PandocMacroLoop String
71 | PandocMacroLoop String
72+ | PandocUTF8DecodingError String Int Word8
70 deriving (Show, Typeable, Generic)
73 deriving (Show, Typeable, Generic)
72instance Exception PandocError
75instance Exception PandocError
@@ -117,6 +120,10 @@ handleError (Left e) =
117 "EPUB subdirectory name '" ++ s ++ "' contains illegal characters"
120 "EPUB subdirectory name '" ++ s ++ "' contains illegal characters"
118 PandocMacroLoop s -> err 91 $
121 PandocMacroLoop s -> err 91 $
119 "Loop encountered in expanding macro " ++ s
122 "Loop encountered in expanding macro " ++ s
123+ PandocUTF8DecodingError f offset w -> err 92 $
124+ "UTF-8 decoding error in " ++ f ++ " at byte offset " ++ show offset ++
125+ " (" ++ printf "%2x" w ++ ").\n" ++
126+ "The input must be a UTF-8 encoded text."
121err :: Int -> String -> IO a
128err :: Int -> String -> IO a
122err exitCode msg = do
129err exitCode msg = do