{-# 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 showList :: [SQLErrorCode] -> ShowS $cshowList :: [SQLErrorCode] -> ShowS show :: SQLErrorCode -> String $cshow :: SQLErrorCode -> String showsPrec :: Int -> SQLErrorCode -> ShowS $cshowsPrec :: Int -> SQLErrorCode -> ShowS Show, SQLErrorCode -> SQLErrorCode -> Bool (SQLErrorCode -> SQLErrorCode -> Bool) -> (SQLErrorCode -> SQLErrorCode -> Bool) -> Eq SQLErrorCode forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: SQLErrorCode -> SQLErrorCode -> Bool $c/= :: SQLErrorCode -> SQLErrorCode -> Bool == :: SQLErrorCode -> SQLErrorCode -> Bool $c== :: 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 enumFromThenTo :: SQLErrorCode -> SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] $cenumFromThenTo :: SQLErrorCode -> SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] enumFromTo :: SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] $cenumFromTo :: SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] enumFromThen :: SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] $cenumFromThen :: SQLErrorCode -> SQLErrorCode -> [SQLErrorCode] enumFrom :: SQLErrorCode -> [SQLErrorCode] $cenumFrom :: SQLErrorCode -> [SQLErrorCode] fromEnum :: SQLErrorCode -> Int $cfromEnum :: SQLErrorCode -> Int toEnum :: Int -> SQLErrorCode $ctoEnum :: Int -> SQLErrorCode pred :: SQLErrorCode -> SQLErrorCode $cpred :: SQLErrorCode -> SQLErrorCode succ :: SQLErrorCode -> SQLErrorCode $csucc :: 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 showList :: [SQLException] -> ShowS $cshowList :: [SQLException] -> ShowS show :: SQLException -> String $cshow :: SQLException -> String showsPrec :: Int -> SQLException -> ShowS $cshowsPrec :: Int -> SQLException -> ShowS Show, SQLException -> SQLException -> Bool (SQLException -> SQLException -> Bool) -> (SQLException -> SQLException -> Bool) -> Eq SQLException forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a /= :: SQLException -> SQLException -> Bool $c/= :: SQLException -> SQLException -> Bool == :: SQLException -> SQLException -> Bool $c== :: SQLException -> SQLException -> Bool Eq, Typeable) instance Exception SQLException throwSQLException :: MonadDOM m => SQLError -> m a throwSQLException :: 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 (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 :: SQLErrorCode -> String -> SQLException SQLException{String SQLErrorCode sqlErrorMessage :: String sqlErrorCode :: SQLErrorCode sqlErrorMessage :: String sqlErrorCode :: SQLErrorCode ..})