mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-11-26 11:57:01 +03:00
Add error position
This commit is contained in:
parent
cf6458fe76
commit
9276d7e298
@ -80,7 +80,16 @@ serverError =
|
|||||||
LibPQ.resultErrorField result LibPQ.DiagMessageDetail
|
LibPQ.resultErrorField result LibPQ.DiagMessageDetail
|
||||||
hint <-
|
hint <-
|
||||||
LibPQ.resultErrorField result LibPQ.DiagMessageHint
|
LibPQ.resultErrorField result LibPQ.DiagMessageHint
|
||||||
pure $ Left $ ServerError code message detail hint
|
position <-
|
||||||
|
parsePosition <$> LibPQ.resultErrorField result LibPQ.DiagStatementPosition
|
||||||
|
pure $ Left $ ServerError code message detail hint position
|
||||||
|
where
|
||||||
|
parsePosition = \case
|
||||||
|
Nothing -> Nothing
|
||||||
|
Just pos ->
|
||||||
|
case Attoparsec.parseOnly (Attoparsec.decimal <* Attoparsec.endOfInput) pos of
|
||||||
|
Right pos -> Just pos
|
||||||
|
_ -> Nothing
|
||||||
|
|
||||||
{-# INLINE maybe #-}
|
{-# INLINE maybe #-}
|
||||||
maybe :: Row.Row a -> Result (Maybe a)
|
maybe :: Row.Row a -> Result (Maybe a)
|
||||||
|
@ -54,6 +54,9 @@ data ResultError
|
|||||||
-- This is intended to differ from detail in that it offers advice
|
-- This is intended to differ from detail in that it offers advice
|
||||||
-- (potentially inappropriate) rather than hard facts. Might run to
|
-- (potentially inappropriate) rather than hard facts. Might run to
|
||||||
-- multiple lines.
|
-- multiple lines.
|
||||||
|
(Maybe Int)
|
||||||
|
-- ^ __Position__. Error cursor position as an index into the original
|
||||||
|
-- statement string. Positions are measured in characters not bytes.
|
||||||
| -- |
|
| -- |
|
||||||
-- The database returned an unexpected result.
|
-- The database returned an unexpected result.
|
||||||
-- Indicates an improper statement or a schema mismatch.
|
-- Indicates an improper statement or a schema mismatch.
|
||||||
|
@ -153,7 +153,7 @@ tree =
|
|||||||
where
|
where
|
||||||
resultTest =
|
resultTest =
|
||||||
\case
|
\case
|
||||||
Right (Left (Session.QueryError _ _ (Session.ResultError (Session.ServerError "26000" _ _ _)))) -> False
|
Right (Left (Session.QueryError _ _ (Session.ResultError (Session.ServerError "26000" _ _ _ _)))) -> False
|
||||||
_ -> True
|
_ -> True
|
||||||
session =
|
session =
|
||||||
catchError session (const (pure ())) *> session
|
catchError session (const (pure ())) *> session
|
||||||
|
Loading…
Reference in New Issue
Block a user