@@ -38,11 +38,13 @@ module Text.Pandoc.Error (
3838import Prelude
3939import Control.Exception (Exception)
4040import Data.Typeable (Typeable)
41+import Data.Word (Word8)
4142import GHC.Generics (Generic)
4243import Network.HTTP.Client (HttpException)
4344import System.Exit (ExitCode (..), exitWith)
4445import System.IO (stderr)
4546import qualified Text.Pandoc.UTF8 as UTF8
47+import Text.Printf (printf)
4648import Text.Parsec.Error
4749import Text.Parsec.Pos hiding (Line)
4850
@@ -67,6 +69,7 @@ data PandocError = PandocIOError String IOError
6769 | PandocAppError String
6870 | PandocEpubSubdirectoryError String
6971 | PandocMacroLoop String
72+ | PandocUTF8DecodingError String Int Word8
7073 deriving (Show, Typeable, Generic)
7174
7275instance Exception PandocError
@@ -117,6 +120,10 @@ handleError (Left e) =
117120 "EPUB subdirectory name '" ++ s ++ "' contains illegal characters"
118121 PandocMacroLoop s -> err 91 $
119122 "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."
120127
121128err :: Int -> String -> IO a
122129err exitCode msg = do