|
1 |
| -{-# LANGUAGE DeriveGeneric #-} |
2 |
| -{-# LANGUAGE LambdaCase #-} |
3 |
| -{-# LANGUAGE OverloadedStrings #-} |
4 | 1 | {-# LANGUAGE RankNTypes #-}
|
5 | 2 |
|
6 | 3 | module Cardano.Db.Error (
|
7 |
| - AsDbError (..), |
| 4 | + -- AsDbError (..), |
8 | 5 | CallSite (..),
|
9 | 6 | DbError (..),
|
10 | 7 | runOrThrowIODb,
|
11 | 8 | runOrThrowIO,
|
12 | 9 | logAndThrowIO,
|
13 |
| - base16encode |
| 10 | + base16encode, |
14 | 11 | ) where
|
15 | 12 |
|
16 | 13 | import Cardano.BM.Trace (Trace, logError)
|
17 |
| -import Cardano.Db.Schema.Ids |
18 |
| -import Cardano.Prelude (throwIO, MonadIO) |
| 14 | +import Cardano.Prelude (MonadIO, throwIO) |
19 | 15 | import Control.Exception (Exception)
|
| 16 | +import qualified Data.ByteString.Base16 as Base16 |
20 | 17 | import Data.ByteString.Char8 (ByteString)
|
21 | 18 | import Data.Text (Text)
|
22 |
| -import Data.Word (Word16, Word64) |
23 |
| -import GHC.Generics (Generic) |
24 |
| -import qualified Data.ByteString.Base16 as Base16 |
25 | 19 | import qualified Data.Text.Encoding as Text
|
26 |
| -import qualified Hasql.Session as HsqlS |
27 | 20 |
|
28 |
| -class AsDbError e where |
29 |
| - toDbError :: DbError -> e |
30 |
| - fromDbError :: e -> Maybe DbError |
| 21 | +import qualified Hasql.Session as HsqlSes |
31 | 22 |
|
32 |
| -data DbError |
33 |
| - = DbError !CallSite !Text !HsqlS.SessionError |
34 |
| - | DbLookupError !CallSite !Text !LookupContext |
35 |
| - deriving (Show, Eq) |
| 23 | +data DbError = DbError |
| 24 | + { dbErrorCallSite :: !CallSite |
| 25 | + , dbErrorMessage :: !Text |
| 26 | + , dbErrorCause :: !(Maybe HsqlSes.SessionError) -- Now a Maybe |
| 27 | + } |
| 28 | + |
| 29 | +-- class AsDbError e where |
| 30 | +-- toDbError :: DbError -> e |
| 31 | +-- fromDbError :: e -> Maybe DbError |
| 32 | + |
| 33 | +-- data DbError |
| 34 | +-- = DbError !CallSite !Text !HsqlS.SessionError |
| 35 | +-- | DbLookupError !CallSite !Text !LookupContext |
| 36 | +-- deriving (Show, Eq) |
36 | 37 |
|
37 |
| -instance Exception DbError |
| 38 | +-- instance Exception DbError |
38 | 39 |
|
39 | 40 | data CallSite = CallSite
|
40 | 41 | { csModule :: !Text
|
41 | 42 | , csFile :: !Text
|
42 | 43 | , csLine :: !Int
|
43 |
| - } deriving (Show, Eq) |
44 |
| - |
45 |
| -data LookupContext |
46 |
| - = BlockHashContext !ByteString |
47 |
| - | BlockIdContext !Word64 |
48 |
| - | MessageContext !Text |
49 |
| - | TxHashContext !ByteString |
50 |
| - | TxOutPairContext !ByteString !Word16 |
51 |
| - | EpochNoContext !Word64 |
52 |
| - | SlotNoContext !Word64 |
53 |
| - | GovActionPairContext !TxId !Word64 |
54 |
| - | MetaEmptyContext |
55 |
| - | MetaMultipleRowsContext |
56 |
| - | MultipleGenesisContext |
57 |
| - | ExtraMigrationContext !String |
58 |
| - | PruneConsumedContext !String |
59 |
| - | RJsonbInSchemaContext !String |
60 |
| - | TxOutVariantContext !String |
61 |
| - deriving (Show, Eq, Generic) |
62 |
| - |
63 |
| -instance Exception LookupContext |
| 44 | + } |
| 45 | + deriving (Show, Eq) |
| 46 | + |
| 47 | +-- data LookupContext |
| 48 | +-- = BlockHashContext !ByteString |
| 49 | +-- | BlockIdContext !Word64 |
| 50 | +-- | MessageContext !Text |
| 51 | +-- | TxHashContext !ByteString |
| 52 | +-- | TxOutPairContext !ByteString !Word16 |
| 53 | +-- | EpochNoContext !Word64 |
| 54 | +-- | SlotNoContext !Word64 |
| 55 | +-- | GovActionPairContext !TxId !Word64 |
| 56 | +-- | MetaEmptyContext |
| 57 | +-- | MetaMultipleRowsContext |
| 58 | +-- | MultipleGenesisContext |
| 59 | +-- | ExtraMigrationContext !String |
| 60 | +-- | PruneConsumedContext !String |
| 61 | +-- | RJsonbInSchemaContext !String |
| 62 | +-- | TxOutVariantContext !String |
| 63 | +-- deriving (Show, Eq, Generic) |
| 64 | + |
| 65 | +-- instance Exception LookupContext |
64 | 66 |
|
65 | 67 | -- catchDbError :: String -> HsqlT.Transaction a -> HsqlT.Transaction a
|
66 | 68 | -- catchDbError context action =
|
67 | 69 | -- action `catch` \e ->
|
68 | 70 | -- throwError $ DbError $ context ++ ": " ++ show e
|
69 | 71 |
|
70 |
| - |
71 | 72 | -- instance Show LookupFail where
|
72 | 73 | -- show =
|
73 | 74 | -- \case
|
|
0 commit comments