{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE DeriveDataTypeable #-} module JSDOM.Custom.SQLError ( module Generated , SQLErrorCode(..) , SQLException(..) , throwSQLException ) where import Prelude () import Prelude.Compat import Data.Typeable (Typeable) import Control.Exception (Exception, throwIO) import Control.Monad.IO.Class (MonadIO(..)) import JSDOM.Types (MonadDOM(..)) import JSDOM.Generated.SQLError as Generated data SQLErrorCode = SQLErrorUnknown | SQLErrorDatabase | SQLErrorVersion | SQLErrorTooLarge | SQLErrorQuota | SQLErrorSyntax | SQLErrorConstraint | SQLErrorTimeout deriving (Int -> SQLErrorCode -> ShowS [SQLErrorCode] -> ShowS SQLErrorCode -> String (Int -> SQLErrorCode -> ShowS) -> (SQLErrorCode -> String) -> ([SQLErrorCode] -> ShowS) -> Show SQLErrorCode forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a $cshowsPrec :: Int -> SQLErrorCode -> ShowS showsPrec :: Int -> SQLErrorCode -> ShowS $cshow :: SQLErrorCode -> String show :: SQLErrorCode -> String $cshowList :: [SQLErrorCode] -> ShowS showList :: [SQLErrorCode] -> ShowS Show, SQLErrorCode -> SQLErrorCode -> Bool (SQLErrorCode -> SQLErrorCode -> Bool) -> (SQLErrorCode -> SQLErrorCode -> Bool) -> Eq SQLErrorCode forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a $c== :: SQLErrorCode -> SQLErrorCode -> Bool == :: SQLErrorCode -> SQLErrorCode -> Bool $c/= :: SQLErrorCode -> SQLErrorCode -> Bool /= :: SQLErrorCode -> SQLErrorCode -> Bool Eq, Int -> SQLErrorCode SQLErrorCode -> Int SQLErrorCode -> [SQLErrorCode] SQLErrorCode -> SQLErrorCode SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] SQLErrorCode -> SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] (SQLErrorCode -> SQLErrorCode) -> (SQLErrorCode -> SQLErrorCode) -> (Int -> SQLErrorCode) -> (SQLErrorCode -> Int) -> (SQLErrorCode -> [SQLErrorCode]) -> (SQLErrorCode -> SQLErrorCode -> [SQLErrorCode]) -> (SQLErrorCode -> SQLErrorCode -> [SQLErrorCode]) -> (SQLErrorCode -> SQLErrorCode -> SQLErrorCode -> [SQLErrorCode]) -> Enum SQLErrorCode forall a. (a -> a) -> (a -> a) -> (Int -> a) -> (a -> Int) -> (a -> [a]) -> (a -> a -> [a]) -> (a -> a -> [a]) -> (a -> a -> a -> [a]) -> Enum a $csucc :: SQLErrorCode -> SQLErrorCode succ :: SQLErrorCode -> SQLErrorCode $cpred :: SQLErrorCode -> SQLErrorCode pred :: SQLErrorCode -> SQLErrorCode $ctoEnum :: Int -> SQLErrorCode toEnum :: Int -> SQLErrorCode $cfromEnum :: SQLErrorCode -> Int fromEnum :: SQLErrorCode -> Int $cenumFrom :: SQLErrorCode -> [SQLErrorCode] enumFrom :: SQLErrorCode -> [SQLErrorCode] $cenumFromThen :: SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] enumFromThen :: SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] $cenumFromTo :: SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] enumFromTo :: SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] $cenumFromThenTo :: SQLErrorCode -> SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] enumFromThenTo :: SQLErrorCode -> SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] Enum, Typeable) data SQLException = SQLException { SQLException -> SQLErrorCode sqlErrorCode :: SQLErrorCode, SQLException -> String sqlErrorMessage :: String } deriving (Int -> SQLException -> ShowS [SQLException] -> ShowS SQLException -> String (Int -> SQLException -> ShowS) -> (SQLException -> String) -> ([SQLException] -> ShowS) -> Show SQLException forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a $cshowsPrec :: Int -> SQLException -> ShowS showsPrec :: Int -> SQLException -> ShowS $cshow :: SQLException -> String show :: SQLException -> String $cshowList :: [SQLException] -> ShowS showList :: [SQLException] -> ShowS Show, SQLException -> SQLException -> Bool (SQLException -> SQLException -> Bool) -> (SQLException -> SQLException -> Bool) -> Eq SQLException forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a $c== :: SQLException -> SQLException -> Bool == :: SQLException -> SQLException -> Bool $c/= :: SQLException -> SQLException -> Bool /= :: SQLException -> SQLException -> Bool Eq, Typeable) instance Exception SQLException throwSQLException :: MonadDOM m => SQLError -> m a throwSQLException :: forall (m :: * -> *) a. MonadDOM m => SQLError -> m a throwSQLException SQLError error = do SQLErrorCode sqlErrorCode <- (Int -> SQLErrorCode forall a. Enum a => Int -> a toEnum (Int -> SQLErrorCode) -> (Word -> Int) -> Word -> SQLErrorCode forall b c a. (b -> c) -> (a -> b) -> a -> c . Int -> Int -> Int forall a. Num a => a -> a -> a subtract Int 1 (Int -> Int) -> (Word -> Int) -> Word -> Int forall b c a. (b -> c) -> (a -> b) -> a -> c . Word -> Int forall a b. (Integral a, Num b) => a -> b fromIntegral) (Word -> SQLErrorCode) -> m Word -> m SQLErrorCode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> SQLError -> m Word forall (m :: * -> *). MonadDOM m => SQLError -> m Word getCode SQLError error String sqlErrorMessage <- SQLError -> m String forall (m :: * -> *) result. (MonadDOM m, FromJSString result) => SQLError -> m result getMessage SQLError error IO a -> m a forall a. IO a -> m a forall (m :: * -> *) a. MonadIO m => IO a -> m a liftIO (IO a -> m a) -> IO a -> m a forall a b. (a -> b) -> a -> b $ SQLException -> IO a forall e a. Exception e => e -> IO a throwIO (SQLException{String SQLErrorCode sqlErrorCode :: SQLErrorCode sqlErrorMessage :: String sqlErrorCode :: SQLErrorCode sqlErrorMessage :: String ..})