@@ -225,7 +225,7 @@ import Data.Text.Internal.Lazy.Fusion (stream, unstream)
225225import Data.Text.Internal.Lazy (Text(..), chunk, empty, foldlChunks,
226226 foldrChunks, smallChunkSize)
227227import Data.Text.Internal (firstf, safe, text)
228−import Data.Text.Lazy.Encoding (decodeUtf8, encodeUtf8)
228+import Data.Text.Lazy.Encoding (decodeUtf8', encodeUtf8)
229229import qualified Data.Text.Internal.Functions as F
230230import Data.Text.Internal.Lazy.Search (indices)
231231#if __GLASGOW_HASKELL__ >= 702
@@ -357,7 +357,11 @@ instance NFData Text where
357357
358358instance Binary Text where
359359 put t = put (encodeUtf8 t)
360− get = P.fmap decodeUtf8 get
360+ get = do
361+ bs <- get
362+ case decodeUtf8' bs of
363+ P.Left exn -> P.fail (P.show exn)
364+ P.Right a -> P.return a
361365
362366-- | This instance preserves data abstraction at the cost of inefficiency.
363367-- We omit reflection services for the sake of data abstraction.