Skip to content

Commit ee4688f

Browse files
committed
rename of NodeSyncError data constructors
1 parent b20d557 commit ee4688f

File tree

10 files changed

+41
-39
lines changed

10 files changed

+41
-39
lines changed

cardano-db-sync/src/Cardano/DbSync/Api.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,15 @@ mkSyncEnvFromConfig trce connString backend syncOptions genCfg syncNodeParams ra
383383
case genCfg of
384384
GenesisCardano _ bCfg sCfg _
385385
| unProtocolMagicId (Byron.configProtocolMagicId bCfg) /= Shelley.sgNetworkMagic (scConfig sCfg) ->
386-
pure . Left . NECardanoConfig $
386+
pure . Left . SNErrCardanoConfig $
387387
mconcat
388388
[ "ProtocolMagicId "
389389
, DB.textShow (unProtocolMagicId $ Byron.configProtocolMagicId bCfg)
390390
, " /= "
391391
, DB.textShow (Shelley.sgNetworkMagic $ scConfig sCfg)
392392
]
393393
| Byron.gdStartTime (Byron.configGenesisData bCfg) /= Shelley.sgSystemStart (scConfig sCfg) ->
394-
pure . Left . NECardanoConfig $
394+
pure . Left . SNErrCardanoConfig $
395395
mconcat
396396
[ "SystemStart "
397397
, DB.textShow (Byron.gdStartTime $ Byron.configGenesisData bCfg)

cardano-db-sync/src/Cardano/DbSync/Cache/Epoch.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ writeEpochBlockDiffToCache ::
7171
ReaderT SqlBackend m (Either SyncNodeError ())
7272
writeEpochBlockDiffToCache cache epCurrent =
7373
case cache of
74-
UninitiatedCache -> pure $ Left $ NEError "writeEpochBlockDiffToCache: Cache is UninitiatedCache"
74+
UninitiatedCache -> pure $ Left $ SNErrDefault "writeEpochBlockDiffToCache: Cache is UninitiatedCache"
7575
Cache ci -> do
7676
cE <- liftIO $ readTVarIO (cEpoch ci)
7777
case (ceMapEpoch cE, ceEpochBlockDiff cE) of
@@ -93,12 +93,12 @@ writeToMapEpochCache syncEnv cache latestEpoch = do
9393
HasLedger hle -> getSecurityParameter $ leProtocolInfo hle
9494
NoLedger nle -> getSecurityParameter $ nleProtocolInfo nle
9595
case cache of
96-
UninitiatedCache -> pure $ Left $ NEError "writeToMapEpochCache: Cache is UninitiatedCache"
96+
UninitiatedCache -> pure $ Left $ SNErrDefault "writeToMapEpochCache: Cache is UninitiatedCache"
9797
Cache ci -> do
9898
-- get EpochBlockDiff so we can use the BlockId we stored when inserting blocks
9999
epochInternalCE <- readEpochBlockDiffFromCache cache
100100
case epochInternalCE of
101-
Nothing -> pure $ Left $ NEError "writeToMapEpochCache: No epochInternalEpochCache"
101+
Nothing -> pure $ Left $ SNErrDefault "writeToMapEpochCache: No epochInternalEpochCache"
102102
Just ei -> do
103103
cE <- liftIO $ readTVarIO (cEpoch ci)
104104
let currentBlockId = ebdBlockId ei

cardano-db-sync/src/Cardano/DbSync/Config/Alonzo.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ readAlonzoGenesisConfig ::
2626
ExceptT SyncNodeError IO AlonzoGenesis
2727
readAlonzoGenesisConfig enc = do
2828
let file = unGenesisFile $ dncAlonzoGenesisFile enc
29-
firstExceptT (NEAlonzoConfig file . renderAlonzoGenesisError) $
29+
firstExceptT (SNErrAlonzoConfig file . renderAlonzoGenesisError) $
3030
readGenesis (GenesisFile file) Nothing
3131

3232
data AlonzoGenesisError

cardano-db-sync/src/Cardano/DbSync/Config/Byron.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{-# LANGUAGE FlexibleInstances #-}
22
{-# LANGUAGE MultiParamTypeClasses #-}
3-
{-# LANGUAGE OverloadedStrings #-}
43
{-# LANGUAGE RankNTypes #-}
54

65
module Cardano.DbSync.Config.Byron (
@@ -20,8 +19,8 @@ readByronGenesisConfig ::
2019
readByronGenesisConfig enc = do
2120
let file = unGenesisFile $ dncByronGenesisFile enc
2221
genHash <-
23-
firstExceptT NEError
22+
firstExceptT SNErrDefault
2423
. hoistEither
2524
$ decodeAbstractHash (unGenesisHashByron $ dncByronGenesisHash enc)
26-
firstExceptT (NEByronConfig file) $
25+
firstExceptT (SNErrByronConfig file) $
2726
Byron.mkConfigFromFile (dncRequiresNetworkMagic enc) file genHash

cardano-db-sync/src/Cardano/DbSync/Config/Shelley.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ readShelleyGenesisConfig ::
3838
ExceptT SyncNodeError IO ShelleyConfig
3939
readShelleyGenesisConfig enc = do
4040
let file = unGenesisFile $ dncShelleyGenesisFile enc
41-
firstExceptT (NEShelleyConfig file . renderShelleyGenesisError) $
41+
firstExceptT (SNErrShelleyConfig file . renderShelleyGenesisError) $
4242
readGenesis (GenesisFile file) Nothing
4343

4444
-- -------------------------------------------------------------------------------------------------

cardano-db-sync/src/Cardano/DbSync/Epoch.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ handleEpochCachingWhenSyncing syncEnv cache newestEpochFromMap epochBlockDiffCac
227227
newEpoch <- DB.queryCalcEpochEntry $ ebdEpochNo currentEpC
228228
writeToMapEpochCache syncEnv cache newEpoch
229229
-- There will always be a EpochBlockDiff at this point in time
230-
(_, _) -> pure $ Left $ NEError "handleEpochCachingWhenSyncing: No caches available to update cache"
230+
(_, _) -> pure $ Left $ SNErrDefault "handleEpochCachingWhenSyncing: No caches available to update cache"
231231

232232
-----------------------------------------------------------------------------------------------------
233233
-- Helper functions

cardano-db-sync/src/Cardano/DbSync/Era/Byron/Insert.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ insertByronTx syncEnv blkId tx blockIndex = do
277277
annotateTx :: SyncNodeError -> SyncNodeError
278278
annotateTx ee =
279279
case ee of
280-
NEInvariant loc ei -> NEInvariant loc (annotateInvariantTx (Byron.taTx tx) ei)
280+
SNErrInvariant loc ei -> SNErrInvariant loc (annotateInvariantTx (Byron.taTx tx) ei)
281281
_other -> ee
282282

283283
insertTxOut ::
@@ -331,13 +331,13 @@ resolveTxInputs txIn@(Byron.TxInUtxo txHash index) = do
331331

332332
calculateTxFee :: Byron.Tx -> [(Byron.TxIn, DB.TxId, DB.TxOutId, DbLovelace)] -> Either SyncNodeError ValueFee
333333
calculateTxFee tx resolvedInputs = do
334-
outval <- first (\e -> NEError $ "calculateTxFee: " <> textShow e) output
334+
outval <- first (\e -> SNErrDefault $ "calculateTxFee: " <> textShow e) output
335335
when (null resolvedInputs) $
336336
Left $
337-
NEError "calculateTxFee: List of transaction inputs is zero."
337+
SNErrDefault "calculateTxFee: List of transaction inputs is zero."
338338
let inval = sum $ map (unDbLovelace . forth4) resolvedInputs
339339
if inval < outval
340-
then Left $ NEInvariant "calculateTxFee" $ EInvInOut inval outval
340+
then Left $ SNErrInvariant "calculateTxFee" $ EInvInOut inval outval
341341
else Right $ ValueFee (DbLovelace outval) (DbLovelace $ inval - outval)
342342
where
343343
output :: Either Byron.LovelaceError Word64

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Genesis.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ insertValidateGenesisDist syncEnv networkName cfg shelleyInitiation = do
6565
-- Setting this to True will log all 'Persistent' operations which is great
6666
-- for debugging, but otherwise *way* too chatty.
6767
when (not shelleyInitiation && (hasInitialFunds || hasStakes)) $ do
68-
liftIO $ logError tracer $ show NEIgnoreShelleyInitiation
69-
throwError NEIgnoreShelleyInitiation
68+
liftIO $ logError tracer $ show SNErrIgnoreShelleyInitiation
69+
throwError SNErrIgnoreShelleyInitiation
7070
if False
7171
then newExceptT $ DB.runDbIohkLogging (envBackend syncEnv) tracer (insertAction hasConsumed prunes)
7272
else newExceptT $ DB.runDbIohkNoLogging (envBackend syncEnv) (insertAction hasConsumed prunes)

cardano-db-sync/src/Cardano/DbSync/Era/Util.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import qualified Data.Text.Encoding.Error as Text
2020

2121
liftLookupFail :: Monad m => Text -> m (Either DB.LookupFail a) -> ExceptT SyncNodeError m a
2222
liftLookupFail loc =
23-
firstExceptT (\lf -> NEError $ mconcat [loc, " ", show lf]) . newExceptT
23+
firstExceptT (\lf -> SNErrDefault $ mconcat [loc, " ", show lf]) . newExceptT
2424

2525
safeDecodeUtf8 :: ByteString -> IO (Either Text.UnicodeException Text)
2626
safeDecodeUtf8 bs

cardano-db-sync/src/Cardano/DbSync/Error.hs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module Cardano.DbSync.Error (
1717
hasAbortOnPanicEnv,
1818
) where
1919

20+
import Cardano.BM.Trace (Trace, logError)
2021
import qualified Cardano.Chain.Genesis as Byron
2122
import qualified Cardano.Chain.UTxO as Byron
2223
import qualified Cardano.Crypto as Crypto (serializeCborHash)
@@ -25,37 +26,38 @@ import Cardano.DbSync.Util
2526
import Cardano.Prelude
2627
import Control.Monad.Trans.Except.Extra (left)
2728
import qualified Data.ByteString.Base16 as Base16
29+
import Data.String (String)
2830
import qualified Data.Text as Text
2931
import qualified Data.Text.Encoding as Text
32+
import GHC.IO.Exception (userError)
3033
import qualified GHC.Show as GShow
31-
import qualified Text.Show as Text
3234
import System.Environment (lookupEnv)
3335
import System.Posix.Process (exitImmediately)
34-
import Cardano.BM.Trace (Trace, logError)
35-
import GHC.IO.Exception (userError)
36+
import qualified Text.Show as Text
3637

3738
data SyncInvariant
3839
= EInvInOut !Word64 !Word64
3940
| EInvTxInOut !Byron.Tx !Word64 !Word64
4041

4142
data SyncNodeError
42-
= NEError !Text
43-
| NEInvariant !Text !SyncInvariant
44-
| NEBlockMismatch !Word64 !ByteString !ByteString
45-
| NEIgnoreShelleyInitiation
46-
| NEByronConfig !FilePath !Byron.ConfigurationError
47-
| NEShelleyConfig !FilePath !Text
48-
| NEAlonzoConfig !FilePath !Text
49-
| NECardanoConfig !Text
43+
= SNErrDefault !Text
44+
| SNErrInvariant !Text !SyncInvariant
45+
| SNEErrBlockMismatch !Word64 !ByteString !ByteString
46+
| SNErrIgnoreShelleyInitiation
47+
| SNErrByronConfig !FilePath !Byron.ConfigurationError
48+
| SNErrShelleyConfig !FilePath !Text
49+
| SNErrAlonzoConfig !FilePath !Text
50+
| SNErrCardanoConfig !Text
51+
| SNErrInsertGenesis !String
5052

5153
instance Exception SyncNodeError
5254

5355
instance Show SyncNodeError where
5456
show =
5557
\case
56-
NEError t -> "Error: " <> Text.show t
57-
NEInvariant loc i -> Text.show loc <> ": " <> Text.show (renderSyncInvariant i)
58-
NEBlockMismatch blkNo hashDb hashBlk ->
58+
SNErrDefault t -> "Error: " <> Text.show t
59+
SNErrInvariant loc i -> Text.show loc <> ": " <> Text.show (renderSyncInvariant i)
60+
SNEErrBlockMismatch blkNo hashDb hashBlk ->
5961
mconcat
6062
[ "Block mismatch for block number "
6163
, show blkNo
@@ -64,38 +66,39 @@ instance Show SyncNodeError where
6466
, " but chain provided "
6567
, Text.show $ bsBase16Encode hashBlk
6668
]
67-
NEIgnoreShelleyInitiation ->
69+
SNErrIgnoreShelleyInitiation ->
6870
mconcat
6971
[ "Node configs that don't fork to Shelley directly and initiate"
7072
, " funds or stakes in Shelley Genesis are not supported."
7173
]
72-
NEByronConfig fp ce ->
74+
SNErrByronConfig fp ce ->
7375
mconcat
7476
[ "Failed reading Byron genesis file "
7577
, Text.show $ textShow fp
7678
, ": "
7779
, Text.show $ textShow ce
7880
]
79-
NEShelleyConfig fp txt ->
81+
SNErrShelleyConfig fp txt ->
8082
mconcat
8183
[ "Failed reading Shelley genesis file "
8284
, Text.show $ textShow fp
8385
, ": "
8486
, show txt
8587
]
86-
NEAlonzoConfig fp txt ->
88+
SNErrAlonzoConfig fp txt ->
8789
mconcat
8890
[ "Failed reading Alonzo genesis file "
8991
, Text.show $ textShow fp
9092
, ": "
9193
, show txt
9294
]
93-
NECardanoConfig err ->
95+
SNErrCardanoConfig err ->
9496
mconcat
9597
[ "With Cardano protocol, Byron/Shelley config mismatch:\n"
9698
, " "
9799
, show err
98100
]
101+
SNErrInsertGenesis err -> "Error InsertGenesis: " <> err
99102

100103
annotateInvariantTx :: Byron.Tx -> SyncInvariant -> SyncInvariant
101104
annotateInvariantTx tx ei =
@@ -104,10 +107,10 @@ annotateInvariantTx tx ei =
104107
_other -> ei
105108

106109
dbSyncNodeError :: Monad m => Text -> ExceptT SyncNodeError m a
107-
dbSyncNodeError = left . NEError
110+
dbSyncNodeError = left . SNErrDefault
108111

109112
dbSyncInvariant :: Monad m => Text -> SyncInvariant -> ExceptT SyncNodeError m a
110-
dbSyncInvariant loc = left . NEInvariant loc
113+
dbSyncInvariant loc = left . SNErrInvariant loc
111114

112115
renderSyncInvariant :: SyncInvariant -> Text
113116
renderSyncInvariant ei =

0 commit comments

Comments
 (0)