summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorBodigrim <andrew.lelechenko@gmail.com>2022-04-13 18:41:46 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-04-22 02:14:48 -0400
commit252394cefa746cb9eaf4fed4ea23d716eab20d1b (patch)
tree549f78656994f0cee86f78c54b13133303e96790 /libraries
parentfcf22883774fab6e77058d981a3f840fa663e3ac (diff)
downloadhaskell-252394cefa746cb9eaf4fed4ea23d716eab20d1b.tar.gz
Improve error messages from GHC.IO.Encoding.Failure
Diffstat (limited to 'libraries')
-rw-r--r--libraries/base/GHC/IO/Encoding/Failure.hs20
1 files changed, 12 insertions, 8 deletions
diff --git a/libraries/base/GHC/IO/Encoding/Failure.hs b/libraries/base/GHC/IO/Encoding/Failure.hs
index a26e3f8fcc..5b8de73b6b 100644
--- a/libraries/base/GHC/IO/Encoding/Failure.hs
+++ b/libraries/base/GHC/IO/Encoding/Failure.hs
@@ -148,7 +148,9 @@ recoverDecode cfm input@Buffer{ bufRaw=iraw, bufL=ir, bufR=_ }
output@Buffer{ bufRaw=oraw, bufL=_, bufR=ow } =
--puts $ "recoverDecode " ++ show ir
case cfm of
- ErrorOnCodingFailure -> ioe_decodingError
+ ErrorOnCodingFailure -> do
+ b <- readWord8Buf iraw ir
+ ioe_decodingError b
IgnoreCodingFailure -> return (input { bufL=ir+1 }, output)
TransliterateCodingFailure -> do
ow' <- writeCharBuf oraw ow unrepresentableChar
@@ -189,15 +191,17 @@ recoverEncode cfm input@Buffer{ bufRaw=iraw, bufL=ir, bufR=_ }
RoundtripFailure | Just x <- unescapeRoundtripCharacterSurrogate c -> do
writeWord8Buf oraw ow x
return (input { bufL=ir' }, output { bufR=ow+1 })
- _ -> ioe_encodingError
+ _ -> ioe_encodingError c
-ioe_decodingError :: IO a
-ioe_decodingError = ioException
+ioe_decodingError :: Word8 -> IO a
+ioe_decodingError b = ioException
(IOError Nothing InvalidArgument "recoverDecode"
- "invalid byte sequence" Nothing Nothing)
+ ("cannot decode byte sequence starting from " ++ show b) Nothing Nothing)
-ioe_encodingError :: IO a
-ioe_encodingError = ioException
+ioe_encodingError :: Char -> IO a
+ioe_encodingError ch = ioException
(IOError Nothing InvalidArgument "recoverEncode"
- "invalid character" Nothing Nothing)
+ -- This assumes that @show ch@ escapes non-ASCII symbols
+ -- and thus does not cause recursive encoding failures.
+ ("cannot encode character " ++ show ch) Nothing Nothing)