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 ,
@@ -14,53 +11,57 @@ module Cardano.Db.Error (
14
11
) where
15
12
16
13
import Cardano.BM.Trace (Trace , logError )
17
- import Cardano.Db.Schema.Ids
18
14
import Cardano.Prelude (throwIO , MonadIO )
19
15
import Control.Exception (Exception )
20
16
import Data.ByteString.Char8 (ByteString )
21
17
import Data.Text (Text )
22
- import Data.Word (Word16 , Word64 )
23
- import GHC.Generics (Generic )
24
18
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
+ }
36
28
37
- instance Exception DbError
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)
37
+
38
+ -- instance Exception DbError
38
39
39
40
data CallSite = CallSite
40
41
{ csModule :: ! Text
41
42
, csFile :: ! Text
42
43
, csLine :: ! Int
43
44
} deriving (Show , Eq )
44
45
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
46
+ -- data LookupContext
47
+ -- = BlockHashContext !ByteString
48
+ -- | BlockIdContext !Word64
49
+ -- | MessageContext !Text
50
+ -- | TxHashContext !ByteString
51
+ -- | TxOutPairContext !ByteString !Word16
52
+ -- | EpochNoContext !Word64
53
+ -- | SlotNoContext !Word64
54
+ -- | GovActionPairContext !TxId !Word64
55
+ -- | MetaEmptyContext
56
+ -- | MetaMultipleRowsContext
57
+ -- | MultipleGenesisContext
58
+ -- | ExtraMigrationContext !String
59
+ -- | PruneConsumedContext !String
60
+ -- | RJsonbInSchemaContext !String
61
+ -- | TxOutVariantContext !String
62
+ -- deriving (Show, Eq, Generic)
63
+
64
+ -- instance Exception LookupContext
64
65
65
66
-- catchDbError :: String -> HsqlT.Transaction a -> HsqlT.Transaction a
66
67
-- catchDbError context action =
0 commit comments