Add error position

This commit is contained in:
Nikita Volkov 2022-07-07 10:47:11 +03:00
parent cf6458fe76
commit 9276d7e298
3 changed files with 14 additions and 2 deletions

View File

@ -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)

View File

@ -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.

View File

@ -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