Skip to content

Commit c77670e

Browse files
committed
Add HasCallStack at error sites and improve Dijkstra error messages
Add HasCallStack constraints to standalone functions that call error directly or indirectly. Improve bare Dijkstra-era placeholder error messages to follow the convention: functionName: Dijkstra era not supported.
1 parent 526f50b commit c77670e

9 files changed

Lines changed: 26 additions & 15 deletions

File tree

cardano-api/src/Cardano/Api/Certificate/Internal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ getAnchorDataFromCertificate c =
826826
Ledger.RetirePoolTxCert _ _ -> return Nothing
827827
Ledger.GenesisDelegTxCert{} -> return Nothing
828828
Ledger.MirTxCert _ -> return Nothing
829-
_ -> error "dijkstra"
829+
_ -> error "getAnchorDataFromCertificate: Dijkstra era not supported"
830830
ConwayCertificate ceo ccert ->
831831
conwayEraOnwardsConstraints ceo $
832832
case ccert of
@@ -843,7 +843,7 @@ getAnchorDataFromCertificate c =
843843
Ledger.UpdateDRepTxCert _ mAnchor -> return $ Ledger.strictMaybeToMaybe mAnchor
844844
Ledger.AuthCommitteeHotKeyTxCert _ _ -> return Nothing
845845
Ledger.ResignCommitteeColdTxCert _ mAnchor -> return $ Ledger.strictMaybeToMaybe mAnchor
846-
_ -> error "dijkstra"
846+
_ -> error "getAnchorDataFromCertificate: Dijkstra era not supported"
847847
where
848848
anchorDataFromPoolMetadata
849849
:: MonadError AnchorDataFromCertificateError m

cardano-api/src/Cardano/Api/Experimental/Tx/Internal/AnyWitness.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ getPlutusDatum
125125
getPlutusDatum L.SPlutusV1 (SpendingScriptDatum d) = Just d
126126
getPlutusDatum L.SPlutusV2 (SpendingScriptDatum d) = Just d
127127
getPlutusDatum L.SPlutusV3 (SpendingScriptDatum d) = d
128-
getPlutusDatum L.SPlutusV4 (SpendingScriptDatum _d) = error "dijkstra"
128+
getPlutusDatum L.SPlutusV4 (SpendingScriptDatum _d) = error "getPlutusDatum: Dijkstra era not supported"
129129
getPlutusDatum _ InlineDatum = Nothing
130130
getPlutusDatum _ NoScriptDatum = Nothing
131131

cardano-api/src/Cardano/Api/Key/Internal/Class.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Cardano.Crypto.Seed qualified as Crypto
2222

2323
import Control.Monad.IO.Class
2424
import Data.Kind (Type)
25+
import GHC.Stack (HasCallStack)
2526
import System.Random (StdGen)
2627
import System.Random qualified as Random
2728

@@ -77,7 +78,8 @@ generateSigningKey keytype = do
7778
seedSize = deterministicSigningKeySeedSize keytype
7879

7980
generateInsecureSigningKey
80-
:: MonadIO m
81+
:: HasCallStack
82+
=> MonadIO m
8183
=> Key keyrole
8284
=> SerialiseAsRawBytes (SigningKey keyrole)
8385
=> StdGen

cardano-api/src/Cardano/Api/LedgerState.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ import Data.Word
270270
import Data.Yaml qualified as Yaml
271271
import Formatting.Buildable (build)
272272
import GHC.Exts (IsList (..))
273+
import GHC.Stack (HasCallStack)
273274
import Lens.Micro
274275
import Network.Mux qualified as Mux
275276
import Network.TypedProtocol.Core (Nat (..))
@@ -458,7 +459,7 @@ data FoldStatus
458459
-- the node's tip where @k@ is the security parameter.
459460
foldBlocks
460461
:: forall a t m
461-
. ()
462+
. HasCallStack
462463
=> Show a
463464
=> MonadIOTransError FoldBlocksError t m
464465
=> NodeConfigFile 'In
@@ -715,7 +716,8 @@ foldBlocks nodeConfigFilePath socketPath validationMode state0 accumulate = hand
715716
-- | Wrap a 'ChainSyncClient' with logic that tracks the ledger state.
716717
chainSyncClientWithLedgerState
717718
:: forall m a
718-
. Monad m
719+
. HasCallStack
720+
=> Monad m
719721
=> Env
720722
-> LedgerState
721723
-- ^ Initial ledger state
@@ -859,7 +861,8 @@ chainSyncClientWithLedgerState env ledgerState0 validationMode (CS.ChainSyncClie
859861
-- | See 'chainSyncClientWithLedgerState'.
860862
chainSyncClientPipelinedWithLedgerState
861863
:: forall m a
862-
. Monad m
864+
. HasCallStack
865+
=> Monad m
863866
=> Env
864867
-> LedgerState
865868
-> ValidationMode
@@ -2308,7 +2311,8 @@ getLedgerTablesUTxOValues sbe tbs =
23082311
-- provide a termination epoch otherwise blocks would be applied indefinitely.
23092312
foldEpochState
23102313
:: forall t m s
2311-
. MonadIOTransError FoldBlocksError t m
2314+
. HasCallStack
2315+
=> MonadIOTransError FoldBlocksError t m
23122316
=> NodeConfigFile 'In
23132317
-- ^ Path to the cardano-node config file (e.g. <path to cardano-node project>/configuration/cardano/mainnet-config.json)
23142318
-> SocketPath

cardano-api/src/Cardano/Api/Network/Internal/NetworkId.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import Cardano.Crypto.ProtocolMagic qualified as Byron
2525
import Cardano.Ledger.BaseTypes qualified as Shelley (Network (..))
2626
import Ouroboros.Network.Magic (NetworkMagic (..))
2727

28+
import GHC.Stack (HasCallStack)
29+
2830
-- ----------------------------------------------------------------------------
2931
-- NetworkId type
3032
--
@@ -74,7 +76,7 @@ toShelleyNetwork :: NetworkId -> Shelley.Network
7476
toShelleyNetwork Mainnet = Shelley.Mainnet
7577
toShelleyNetwork (Testnet _) = Shelley.Testnet
7678

77-
fromShelleyNetwork :: Shelley.Network -> NetworkMagic -> NetworkId
79+
fromShelleyNetwork :: HasCallStack => Shelley.Network -> NetworkMagic -> NetworkId
7880
fromShelleyNetwork Shelley.Testnet nm = Testnet nm
7981
fromShelleyNetwork Shelley.Mainnet nm
8082
| nm == mainnetNetworkMagic = Mainnet

cardano-api/src/Cardano/Api/Plutus/Internal/Script.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,8 @@ toShelleyMultiSig = go
14161416
go _ = Left MultiSigErrorTimelockNotsupported
14171417

14181418
-- | Conversion for the 'Shelley.MultiSig' language used by the Shelley era.
1419-
fromShelleyMultiSig :: Shelley.MultiSig (ShelleyLedgerEra ShelleyEra) -> SimpleScript
1419+
fromShelleyMultiSig
1420+
:: Shelley.MultiSig (ShelleyLedgerEra ShelleyEra) -> SimpleScript
14201421
fromShelleyMultiSig = go
14211422
where
14221423
go (Shelley.RequireSignature kh) =
@@ -1425,7 +1426,7 @@ fromShelleyMultiSig = go
14251426
go (Shelley.RequireAllOf s) = RequireAllOf (map go $ toList s)
14261427
go (Shelley.RequireAnyOf s) = RequireAnyOf (map go $ toList s)
14271428
go (Shelley.RequireMOf m s) = RequireMOf m (map go $ toList s)
1428-
go _ = error ""
1429+
go _ = error "fromShelleyMultiSig: Dijkstra era not supported"
14291430

14301431
-- | Conversion for the 'Timelock.Timelock' language that is shared between the
14311432
-- Allegra and Mary eras.
@@ -1459,7 +1460,7 @@ fromAllegraTimelock = go
14591460
go (Shelley.RequireAllOf s) = RequireAllOf (map go (toList s))
14601461
go (Shelley.RequireAnyOf s) = RequireAnyOf (map go (toList s))
14611462
go (Shelley.RequireMOf i s) = RequireMOf i (map go (toList s))
1462-
go _ = error "dijkstra"
1463+
go _ = error "fromAllegraTimelock: Dijkstra era not supported"
14631464

14641465
type family ToLedgerPlutusLanguage lang where
14651466
ToLedgerPlutusLanguage PlutusScriptV1 = Plutus.PlutusV1

cardano-api/src/Cardano/Api/Query/Internal/Type/QueryInMode.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ toConsensusQuery QueryLedgerConfig = Some Consensus.DebugLedgerConfig
572572

573573
toConsensusQueryShelleyBased
574574
:: forall era protocol block result
575-
. ()
575+
. HasCallStack
576576
=> ConsensusBlockForEra era ~ Consensus.ShelleyBlock protocol (ShelleyLedgerEra era)
577577
=> Consensus.CardanoBlock StandardCrypto ~ block
578578
=> L.EraGov (ShelleyLedgerEra era)

cardano-api/src/Cardano/Api/Tx/Internal/Body.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ setTxTreasuryDonation
11851185
:: Maybe (Featured ConwayEraOnwards era L.Coin) -> TxBodyContent build era -> TxBodyContent build era
11861186
setTxTreasuryDonation v txBodyContent = txBodyContent{txTreasuryDonation = v}
11871187

1188-
getTxIdByron :: Byron.ATxAux ByteString -> TxId
1188+
getTxIdByron :: HasCallStack => Byron.ATxAux ByteString -> TxId
11891189
getTxIdByron (Byron.ATxAux{Byron.aTaTx = txbody}) =
11901190
TxId
11911191
. fromMaybe impossible

cardano-api/src/Cardano/Api/Tx/Internal/Sign.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import Data.Text qualified as Text
115115
import Data.Type.Equality (TestEquality (..), (:~:) (Refl))
116116
import Data.Validation qualified as Valid
117117
import GHC.Exts (IsList (..))
118+
import GHC.Stack (HasCallStack)
118119
import Lens.Micro
119120

120121
-- ----------------------------------------------------------------------------
@@ -868,7 +869,8 @@ data ShelleySigningKey
868869
ShelleyExtendedSigningKey Crypto.HD.XPrv
869870

870871
makeShelleySignature
871-
:: Crypto.SignableRepresentation tosign
872+
:: HasCallStack
873+
=> Crypto.SignableRepresentation tosign
872874
=> tosign
873875
-> ShelleySigningKey
874876
-> (Crypto.SignedDSIGN Shelley.DSIGN) tosign

0 commit comments

Comments
 (0)