Skip to content

Commit 3498d5f

Browse files
committed
remove remaining panic from db-sync/db-sync
1 parent aa3620a commit 3498d5f

File tree

7 files changed

+14
-10
lines changed

7 files changed

+14
-10
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import qualified Cardano.Chain.Genesis as Byron
1717
import Cardano.Chain.Update (ApplicationName (..), SoftwareVersion (..))
1818
import qualified Cardano.Crypto.Hash.Class as Crypto
1919
import Cardano.Crypto.ProtocolMagic (ProtocolMagicId (..))
20-
import Cardano.Db (textShow)
2120
import Cardano.DbSync.Config.Alonzo
2221
import Cardano.DbSync.Config.Byron
2322
import Cardano.DbSync.Config.Shelley
@@ -29,7 +28,6 @@ import Cardano.Ledger.Binary.Version
2928
import Cardano.Ledger.Conway.Genesis
3029
import Cardano.Ledger.Keys
3130
import Cardano.Ledger.Shelley.Translation (emptyFromByronTranslationContext)
32-
import Cardano.Prelude (panic)
3331
import Control.Monad.Trans.Except (ExceptT)
3432
import Data.Word (Word64)
3533
import Ouroboros.Consensus.Block.Forging
@@ -140,7 +138,7 @@ shelleyPraosNonce sCfg = Nonce (Crypto.castHash . unGenesisHashShelley $ scGenes
140138
mkProtVer :: Word64 -> Word64 -> ProtVer
141139
mkProtVer a b =
142140
case mkVersion64 a of
143-
Nothing -> panic $ "Impossible: Invalid version generated: " <> textShow a
141+
Nothing -> error $ "Impossible: Invalid version generated: " <> show a
144142
Just v -> ProtVer v (fromIntegral b)
145143

146144
mkByronSoftwareVersion :: SoftwareVersion

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import qualified Data.Set as Set
4242
import qualified Data.Strict.Maybe as Strict
4343
import Database.Persist.SqlBackend.Internal
4444
import Database.Persist.SqlBackend.Internal.StatementCache
45+
import GHC.Err (error)
4546
import Ouroboros.Consensus.Cardano.Block (HardForkBlock (..))
4647
import qualified Ouroboros.Consensus.HardFork.Combinator as Consensus
4748
import Ouroboros.Network.Block (blockHash, blockNo, getHeaderFields, headerFieldBlockNo, unBlockNo)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import Control.Monad.Trans.Control (MonadBaseControl)
2828
import Database.Esqueleto.Experimental (SqlBackend, replace)
2929
import Ouroboros.Consensus.Byron.Ledger (ByronBlock (..))
3030
import Ouroboros.Consensus.Cardano.Block (HardForkBlock (..))
31+
import GHC.Err (error)
3132

3233
-- Populating the Epoch table has two mode:
3334
-- * SyncLagging: when the node is far behind the chain tip and is just updating the DB. In this

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import Database.Esqueleto.Experimental (
4444
(==.),
4545
(^.),
4646
)
47+
import GHC.Err (error)
4748

4849
{- HLINT ignore "Fuse on/on" -}
4950
{- HLINT ignore "Reduce duplication" -}
@@ -126,7 +127,7 @@ queryRewardMap (EpochNo epochNo) = do
126127
collapse :: [(ByteString, (RewardSource, DbLovelace))] -> (ByteString, [(RewardSource, DbLovelace)])
127128
collapse xs =
128129
case xs of
129-
[] -> panic "queryRewardMap.collapse: Unexpected empty list" -- Impossible
130+
[] -> error "queryRewardMap.collapse: Unexpected empty list" -- Impossible
130131
x : _ -> (fst x, List.sort $ map snd xs)
131132

132133
diffRewardMap ::

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ data SyncNodeError
5252
| SNErrInsertGenesis !String
5353
| SNErrLedgerState !String
5454
| SNErrNodeConfig NodeConfigError
55+
| SNErrLocalStateQuery !String
5556

5657
instance Exception SyncNodeError
5758

@@ -110,11 +111,12 @@ instance Show SyncNodeError where
110111
SNErrInsertGenesis err -> "Error SNErrInsertGenesis: " <> err
111112
SNErrLedgerState err -> "Error SNErrLedgerState: " <> err
112113
SNErrNodeConfig err -> "Error SNErrNodeConfig: " <> show err
114+
SNErrLocalStateQuery err -> "Error SNErrLocalStateQuery: " <> show err
113115

114116
data NodeConfigError
115-
= NodeConfigParseError String
116-
| ParseSyncPreConfigError String
117-
| ReadByteStringFromFileError String
117+
= NodeConfigParseError !String
118+
| ParseSyncPreConfigError !String
119+
| ReadByteStringFromFileError !String
118120

119121
instance Exception NodeConfigError
120122

cardano-db-sync/src/Cardano/DbSync/Ledger/State.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ import System.Directory (doesFileExist, listDirectory, removeFile)
119119
import System.FilePath (dropExtension, takeExtension, (</>))
120120
import System.Mem (performMajorGC)
121121
import Prelude (String, id)
122+
import GHC.Err (error)
122123

123124
-- Note: The decision on whether a ledger-state is written to disk is based on the block number
124125
-- rather than the slot number because while the block number is fully populated (for every block

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module Cardano.DbSync.LocalStateQuery (
1111
) where
1212

1313
import Cardano.BM.Trace (Trace, logInfo)
14-
import Cardano.Db (textShow)
1514
import Cardano.DbSync.StateQuery
1615
import Cardano.DbSync.Types
1716
import qualified Cardano.Ledger.BaseTypes as Ledger
@@ -54,6 +53,7 @@ import Ouroboros.Network.Protocol.LocalStateQuery.Client (
5453
)
5554
import qualified Ouroboros.Network.Protocol.LocalStateQuery.Client as StateQuery
5655
import Ouroboros.Network.Protocol.LocalStateQuery.Type (AcquireFailure)
56+
import Cardano.DbSync.Error (SyncNodeError(..))
5757

5858
data NoLedgerEnv = NoLedgerEnv
5959
{ nleTracer :: Trace IO Text
@@ -96,7 +96,7 @@ getSlotDetailsNode nlEnv slot = do
9696
Left _ -> do
9797
einterp2 <- getHistoryInterpreter nlEnv
9898
case evalSlotDetails einterp2 of
99-
Left err -> panic $ "getSlotDetailsNode: " <> textShow err
99+
Left err -> throwIO $ SNErrLocalStateQuery $ "getSlotDetailsNode: " <> Prelude.show err
100100
Right sd -> insertCurrentTime sd
101101
where
102102
interVar = nleHistoryInterpreterVar nlEnv
@@ -123,7 +123,7 @@ getHistoryInterpreter nlEnv = do
123123
res <- atomically $ takeTMVar respVar
124124
case res of
125125
Left err ->
126-
panic $ "getHistoryInterpreter: " <> textShow err
126+
throwIO $ SNErrLocalStateQuery $ "getHistoryInterpreter: " <> Prelude.show err
127127
Right interp -> do
128128
logInfo tracer "getHistoryInterpreter: acquired"
129129
atomically $ writeTVar interVar $ Strict.Just interp

0 commit comments

Comments
 (0)