Skip to content

Commit 57d85bf

Browse files
committed
remove panic from smash server and remove comments
1 parent 3498d5f commit 57d85bf

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ instance Show NodeConfigError where
127127
ParseSyncPreConfigError err -> "ParseSyncPreConfigError - " <> err
128128
ReadByteStringFromFileError err -> "ReadByteStringFromFileError - " <> err
129129

130-
131-
132130
annotateInvariantTx :: Byron.Tx -> SyncInvariant -> SyncInvariant
133131
annotateInvariantTx tx ei =
134132
case ei of

cardano-db-tool/src/Cardano/DbTool/Validate/Ledger.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ validate params genCfg slotNo ledgerFiles =
5555
when logFailure . putStrLn $ redText "Ledger is newer than DB. Trying an older ledger."
5656
go rest False
5757

58-
-- TODO: Vince - Should this throwIO when there is an error as it just prints right now
5958
validateBalance :: SlotNo -> Text -> CardanoLedgerState -> IO ()
6059
validateBalance slotNo addr st = do
6160
balanceDB <- DB.runDbNoLoggingEnv $ DB.queryAddressBalanceAtSlot addr (unSlotNo slotNo)

cardano-smash-server/src/Cardano/SMASH/Server/Config.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import qualified Data.Text as Text
2222
import qualified Data.Text.IO as Text
2323
import qualified Data.Yaml as Yaml
2424
import System.IO.Error
25+
import Cardano.SMASH.Server.Types (DBFail(..))
2526

2627
-- | SMASH Server cli parameters
2728
data SmashServerParams = SmashServerParams
@@ -106,7 +107,7 @@ configureLogging :: FilePath -> Text -> IO (Trace IO Text)
106107
configureLogging fp loggingName = do
107108
bs <- readByteString fp "DbSync" -- only uses the db-sync config
108109
case Yaml.decodeEither' bs of
109-
Left err -> panic $ "readSyncNodeConfig: Error parsing config: " <> textShow err
110+
Left err -> throwIO $ ConfigError ("readSyncNodeConfig: Error parsing config: " <> textShow err)
110111
Right representation -> do
111112
-- Logging.Configuration
112113
logConfig <- Logging.setupFromRepresentation representation
@@ -115,4 +116,4 @@ configureLogging fp loggingName = do
115116
readByteString :: FilePath -> Text -> IO ByteString
116117
readByteString fp cfgType =
117118
catch (BS.readFile fp) $ \(_ :: IOException) ->
118-
panic $ mconcat ["Cannot find the ", cfgType, " configuration file at : ", Text.pack fp]
119+
throwIO $ ConfigError $ mconcat ["Cannot find the ", cfgType, " configuration file at : ", Text.pack fp]

cardano-smash-server/src/Cardano/SMASH/Server/PoolDataLayer.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import qualified Data.Text.Encoding as Text
2121
import Data.Time.Clock (UTCTime)
2222
import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds)
2323
import Database.Persist.Postgresql
24+
import GHC.Err (error)
2425

2526
{- HLINT ignore "Reduce duplication" -}
2627

@@ -52,7 +53,7 @@ postgresqlPoolDataLayer tracer conn =
5253
case mMeta of
5354
Just (tickerName, metadata) -> pure $ Right (TickerName tickerName, PoolMetadataRaw metadata)
5455
Nothing -> pure $ Left $ DbLookupPoolMetadataHash poolId poolMetadataHash
55-
, dlAddPoolMetadata = panic "dlAddPoolMetadata not defined. Will be used only for testing."
56+
, dlAddPoolMetadata = error "dlAddPoolMetadata not defined. Will be used only for testing."
5657
, dlGetReservedTickers = do
5758
tickers <- Db.runPoolDbIohkLogging conn tracer Db.queryReservedTickers
5859
pure $ fmap (\ticker -> (TickerName $ Db.reservedPoolTickerName ticker, dbToServantPoolId $ Db.reservedPoolTickerPoolHash ticker)) tickers
@@ -87,7 +88,7 @@ postgresqlPoolDataLayer tracer conn =
8788
if deleted
8889
then pure $ Right poolHash
8990
else pure $ Left RecordDoesNotExist
90-
, dlAddRetiredPool = \_ _ -> panic "dlAddRetiredPool not defined. Will be used only for testing"
91+
, dlAddRetiredPool = \_ _ -> throwIO $ PoolDataLayerError "dlAddRetiredPool not defined. Will be used only for testing"
9192
, dlCheckRetiredPool = \poolId -> do
9293
actions <- getCertActions tracer conn (Just poolId)
9394
pure $ not <$> isRegistered (servantToDbPoolId poolId) actions

cardano-smash-server/src/Cardano/SMASH/Server/Types.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,16 @@ data DBFail
370370
| TickerAlreadyReserved !TickerName
371371
| RecordDoesNotExist
372372
| DBFail LookupFail
373+
| PoolDataLayerError !Text
374+
| ConfigError !Text
373375
deriving (Eq)
374376

375377
instance ToSchema DBFail where
376378
declareNamedSchema _ =
377379
pure (NamedSchema (Just "DBFail") mempty)
378380

381+
instance Exception DBFail
382+
379383
instance Show DBFail where
380384
show =
381385
\case
@@ -387,6 +391,8 @@ instance Show DBFail where
387391
TickerAlreadyReserved ticker -> "Ticker name " <> Text.show (getTickerName ticker) <> " is already reserved"
388392
RecordDoesNotExist -> "The requested record does not exist."
389393
DBFail lookupFail -> Text.show lookupFail
394+
PoolDataLayerError err -> Text.show err
395+
ConfigError err -> "Config Error: " <> Text.show err
390396

391397
{-
392398
@@ -430,6 +436,16 @@ instance ToJSON DBFail where
430436
[ "code" .= Aeson.String "DBFail"
431437
, "description" .= Aeson.String (Cardano.Prelude.show err)
432438
]
439+
toJSON (PoolDataLayerError err) =
440+
object
441+
[ "code" .= Aeson.String "PoolDataLayerError"
442+
, "description" .= Aeson.String (Cardano.Prelude.show err)
443+
]
444+
toJSON (ConfigError err) =
445+
object
446+
[ "code" .= Aeson.String "ConfigError"
447+
, "description" .= Aeson.String (Cardano.Prelude.show err)
448+
]
433449

434450
-- renderDBFail :: DBFail -> Text
435451
-- renderDBFail (UnknownError err) = "Unknown error. Context: " <> err

doc/validation.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ the fees associated with the transaction are recorded in the database.
7272

7373
## Runtime Reward Validations
7474

75-
-- TODO: Vince - probably too late unless we deprecate, but could this be a command line argument?
76-
7775
Due to recent issues with reward related tables, extra validation was added. When that validation
7876
fails, there are now two options. `db-sync` can abort or continue running. The behaviour is
7977
specified by the presence or absence of the `DbSyncAbortOnPanic` environemnt variable. If the

0 commit comments

Comments
 (0)