From a2cbb9b1047679b6c366a9f9b9c491ba25079658 Mon Sep 17 00:00:00 2001 From: teodanciu Date: Tue, 28 Jun 2022 17:45:28 +0100 Subject: [PATCH] Replace `panic` function from cardano-prelude with `error` --- eras/shelley/impl/src/Cardano/Ledger/Shelley/PoolParams.hs | 5 ++--- libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs | 3 +-- .../cardano-ledger-core/src/Cardano/Ledger/CompactAddress.hs | 5 ++--- .../cardano-ledger-core/src/Cardano/Ledger/Keys/Bootstrap.hs | 5 ++--- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/PoolParams.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/PoolParams.hs index c5f143d5614..440207de0db 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/PoolParams.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/PoolParams.hs @@ -61,7 +61,6 @@ import Cardano.Ledger.Serialization ipv6ToCBOR, ) import Cardano.Ledger.Shelley.Orphans () -import Cardano.Prelude (panic) import Control.DeepSeq (NFData ()) import Data.Aeson (FromJSON (..), ToJSON (..), Value, (.!=), (.:), (.:?), (.=)) import qualified Data.Aeson as Aeson @@ -271,14 +270,14 @@ instance FromCBOR PoolMetadata where data SizeOfPoolOwners = SizeOfPoolOwners instance ToCBOR SizeOfPoolOwners where - toCBOR = panic "The `SizeOfPoolOwners` type cannot be encoded!" + toCBOR = error "The `SizeOfPoolOwners` type cannot be encoded!" -- | The size of the '_poolRelays' 'Set'. Only used to compute size of encoded -- 'PoolParams'. data SizeOfPoolRelays = SizeOfPoolRelays instance ToCBOR SizeOfPoolRelays where - toCBOR = panic "The `SizeOfPoolRelays` type cannot be encoded!" + toCBOR = error "The `SizeOfPoolRelays` type cannot be encoded!" instance CC.Crypto crypto => diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs index 5df55ff0a27..dd9435fba04 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs @@ -87,7 +87,6 @@ import Cardano.Ledger.Keys hashKey, ) import Cardano.Ledger.Slot (SlotNo (..)) -import Cardano.Prelude (panic) import Control.DeepSeq (NFData) import Data.Aeson (FromJSON (..), FromJSONKey (..), ToJSON (..), ToJSONKey (..), (.:), (.=)) import qualified Data.Aeson as Aeson @@ -495,6 +494,6 @@ bootstrapKeyHash (BootstrapAddress byronAddress) = let root = Byron.addrRoot byronAddress bytes = Byron.abstractHashToBytes root !hash = - fromMaybe (panic "bootstrapKeyHash: incorrect hash length") $ + fromMaybe (error "bootstrapKeyHash: incorrect hash length") $ Hash.hashFromBytes bytes in KeyHash hash diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/CompactAddress.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/CompactAddress.hs index f7ae178aea8..34cb4f23326 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/CompactAddress.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/CompactAddress.hs @@ -66,7 +66,6 @@ import qualified Cardano.Ledger.Crypto as CC (Crypto) import Cardano.Ledger.Hashes (ScriptHash (..)) import Cardano.Ledger.Keys (KeyHash (..)) import Cardano.Ledger.Slot (SlotNo (..)) -import Cardano.Prelude (panic) import Control.DeepSeq (NFData) import Control.Monad (ap, guard, unless, when) import qualified Control.Monad.Fail @@ -112,7 +111,7 @@ decompactAddrOld short = snd . unwrap "CompactAddr" $ runGetShort getShortAddr 0 -- is using a CompactAddr, which can only be constructed using compactAddr. -- compactAddr serializes an Addr, so this is guaranteed to work. unwrap :: forall a. Text -> Maybe a -> a - unwrap name = fromMaybe (panic $ "Impossible failure when decoding " <> name) + unwrap name = fromMaybe (error $ "Impossible failure when decoding " <> name) {-# NOINLINE decompactAddrOld #-} ------------------------------------------------------------------------------------------ @@ -594,7 +593,7 @@ decompactAddrLazy (UnsafeCompactAddr bytes) = -- is using a CompactAddr, which can only be constructed using compactAddr. -- compactAddr serializes an Addr, so this is guaranteed to work. unwrap :: forall a. Text -> Maybe a -> a - unwrap name = fromMaybe (panic $ "Impossible failure when decoding " <> name) + unwrap name = fromMaybe (error $ "Impossible failure when decoding " <> name) header = run "address header" 0 bytes getWord addrNetId = unwrap "address network id" $ diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Bootstrap.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Bootstrap.hs index 6ec9c11c1f4..b4cadd103e7 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Bootstrap.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Bootstrap.hs @@ -56,7 +56,6 @@ import Cardano.Ledger.Keys ) import qualified Cardano.Ledger.Keys as Keys import Cardano.Ledger.Serialization (decodeRecordNamed) -import Cardano.Prelude (panic) import Control.DeepSeq (NFData) import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as LBS @@ -185,7 +184,7 @@ unpackByronVKey -- This maybe is produced by a check that the length of the public key -- is the correct one. (32 bytes). If the XPub was constructed correctly, -- we already know that it has this length. - Nothing -> panic "unpackByronVKey: impossible!" + Nothing -> error "unpackByronVKey: impossible!" Just vk -> (VKey vk, ChainCode chainCodeBytes) verifyBootstrapWit :: @@ -204,7 +203,7 @@ verifyBootstrapWit txbodyHash witness = coerceSignature :: WC.XSignature -> DSIGN.SigDSIGN DSIGN.Ed25519DSIGN coerceSignature sig = - fromMaybe (panic "coerceSignature: impossible! signature size mismatch") $ + fromMaybe (error "coerceSignature: impossible! signature size mismatch") $ DSIGN.rawDeserialiseSigDSIGN (WC.unXSignature sig) makeBootstrapWitness ::