Skip to content

Commit

Permalink
Replace panic function from cardano-prelude with error
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Aug 8, 2022
1 parent 1ae63dd commit a2cbb9b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
5 changes: 2 additions & 3 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/PoolParams.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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 =>
Expand Down
3 changes: 1 addition & 2 deletions libs/cardano-ledger-core/src/Cardano/Ledger/Address.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 2 additions & 3 deletions libs/cardano-ledger-core/src/Cardano/Ledger/CompactAddress.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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 #-}

------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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" $
Expand Down
5 changes: 2 additions & 3 deletions libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Bootstrap.hs
Expand Up @@ -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
Expand Down Expand Up @@ -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 ::
Expand All @@ -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 ::
Expand Down

0 comments on commit a2cbb9b

Please sign in to comment.