git.iko.soy/typeable/postgresql-simple
on master help sign in
Fix up "instance Result ST.Text" error handling
commitf96642445954493e2af7d427e065121f6f2ee6f3 authorLeon P Smith <leon@melding-monads.com> dateSun 25 Dec 2011, 02:17 (15 years ago) parentf863b53
1 file changed+6−5
src/Database/PostgreSQL/Simple/Result.hs+6−5
src/Database/PostgreSQL/Simple/Result.hs+6−5
@@ -56,6 +56,7 @@ import qualified Data.ByteString.Char8 as B8
5656import qualified Data.ByteString.Lazy as LB
5757import qualified Data.Text as ST
5858import qualified Data.Text.Encoding as ST
59+import qualified Data.Text.Encoding.Error (UnicodeException)
5960import qualified Data.Text.Lazy as LT
6061
6162-- | Exception thrown if conversion from a SQL value to a Haskell
@@ -90,7 +91,7 @@ class Result a where
9091 --
9192 -- Returns an exception if the conversion fails. In the case of
9293 -- library instances, this will usually be a 'ResultError', but may
93− -- be a 'UnicodeError'.
94+ -- be a 'UnicodeException'.
9495{--
9596instance (Result a) => Result (Maybe a) where
9697 convert _ Nothing = pure Nothing
@@ -159,11 +160,11 @@ instance Result LB.ByteString where
159160
160161
161162instance Result ST.Text where
162− convert f {- | isText f -} = doConvert f okText $ (Right . ST.decodeUtf8)
163−{- | otherwise = incompatible f (typeOf ST.empty)
163+ convert f = doConvert f okText $ (either left Right . ST.decodeUtf8')
164+{- | isText f = doConvert f okText $ (Right . ST.decodeUtf8)
165+ | otherwise = incompatible f (typeOf ST.empty)
164166 "attempt to mix binary and text" -}
165− -- FIXME: return a "Fail someUnicodeError" instead of throwing it
166− -- check character encoding
167+ -- FIXME: check character encoding
167168
168169instance Result LT.Text where
169170 convert f dat = LT.fromStrict <$> convert f dat