Safe Haskell | None |
---|
Module for parsing errors from posgresql error messages. Currently in only parses integrity violation errors (class 23).
Note: Success of parsing may depend on language settings.
- data ConstraintViolation
- constraintViolation :: SqlError -> Maybe ConstraintViolation
- constraintViolationE :: SqlError -> Maybe (SqlError, ConstraintViolation)
- catchViolation :: (SqlError -> ConstraintViolation -> IO a) -> IO a -> IO a
Documentation
data ConstraintViolation Source
NotNullViolation ByteString | The field is a column name |
ForeignKeyViolation ByteString ByteString | Table name and name of violated constraint |
UniqueViolation ByteString | Name of violated constraint |
CheckViolation ByteString ByteString | Relation name (usually table), constraint name |
constraintViolation :: SqlError -> Maybe ConstraintViolationSource
Tries to convert SqlError
to ConstrainViolation
, checks sqlState and
succeedes only if able to parse sqlErrorMsg.
createUser = catchJust constraintViolation catcher $ execute conn ... where catcher UniqueViolation "user_login_key" = ... catcher _ = ...
constraintViolationE :: SqlError -> Maybe (SqlError, ConstraintViolation)Source
Like constraintViolation, but also packs original SqlError.
createUser = catchJust constraintViolationE catcher $ execute conn ... where catcher (_, UniqueViolation "user_login_key") = ... catcher (e, _) = throwIO e
catchViolation :: (SqlError -> ConstraintViolation -> IO a) -> IO a -> IO aSource
Catches SqlError, tries to convert to ConstraintViolation, re-throws on fail. Provides alternative interface to catchJust
createUser = catchViolation catcher $ execute conn ... where catcher _ (UniqueViolation "user_login_key") = ... catcher e _ = throwIO e