Skip to content

Commit 7ea9f5e

Browse files
committed
Upstream Error instances from cardano-cli. Add lens fixities in fourmolu config.
1 parent 23eb6aa commit 7ea9f5e

File tree

9 files changed

+70
-7
lines changed

9 files changed

+70
-7
lines changed

cardano-api/src/Cardano/Api/Experimental/Era.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import Cardano.Api.Era.Internal.Eon.Convert
3939
import Cardano.Api.Era.Internal.Eon.ConwayEraOnwards
4040
import Cardano.Api.Era.Internal.Eon.MaryEraOnwards
4141
import Cardano.Api.Era.Internal.Eon.ShelleyBasedEra (ShelleyBasedEra (..), ShelleyLedgerEra)
42+
import Cardano.Api.Error
4243
import Cardano.Api.Ledger.Internal.Reexport qualified as L
4344
import Cardano.Api.Pretty.Internal.ShowOf
4445

@@ -232,6 +233,10 @@ newtype DeprecatedEra era
232233

233234
deriving via (ShowOf (DeprecatedEra era)) instance Pretty (DeprecatedEra era)
234235

236+
instance Error (DeprecatedEra era) where
237+
prettyError (DeprecatedEra era) =
238+
"The era " <> pretty (show era) <> " is deprecated and no longer supported."
239+
235240
sbeToEra
236241
:: MonadError (DeprecatedEra era) m
237242
=> ShelleyBasedEra era

cardano-api/src/Cardano/Api/Governance/Internal/Action/VotingProcedure.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ module Cardano.Api.Governance.Internal.Action.VotingProcedure where
1717
import Cardano.Api.Address
1818
import Cardano.Api.Era.Internal.Eon.ConwayEraOnwards
1919
import Cardano.Api.Era.Internal.Eon.ShelleyBasedEra
20+
import Cardano.Api.Error
2021
import Cardano.Api.Governance.Internal.Action.ProposalProcedure
2122
import Cardano.Api.HasTypeProxy
2223
import Cardano.Api.Ledger.Internal.Reexport qualified as Ledger
24+
import Cardano.Api.Pretty (pshow)
2325
import Cardano.Api.Serialise.Cbor
2426
import Cardano.Api.Serialise.TextEnvelope.Internal
2527

@@ -144,6 +146,9 @@ newtype VotesMergingConflict era
144146
)
145147
deriving Show
146148

149+
instance Error (VotesMergingConflict era) where
150+
prettyError = pshow
151+
147152
-- | @mergeVotingProcedures vote1 vote2@ merges @vote1@ and @vote2@ into a single vote,
148153
-- or fails if the votes are incompatible.
149154
mergeVotingProcedures

cardano-api/src/Cardano/Api/Governance/Internal/Poll.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module Cardano.Api.Governance.Internal.Poll
3737
where
3838

3939
import Cardano.Api.Era
40+
import Cardano.Api.Error
4041
import Cardano.Api.HasTypeProxy
4142
import Cardano.Api.Hash
4243
import Cardano.Api.Key.Internal
@@ -278,6 +279,9 @@ data GovernancePollError
278279
| ErrGovernancePollInvalidAnswer GovernancePollInvalidAnswerError
279280
deriving Show
280281

282+
instance Error GovernancePollError where
283+
prettyError = pretty . renderGovernancePollError
284+
281285
data GovernancePollInvalidAnswerError = GovernancePollInvalidAnswerError
282286
{ invalidAnswerAcceptableAnswers :: [(Word, Text)]
283287
, invalidAnswerReceivedAnswer :: Word

cardano-api/src/Cardano/Api/Internal/Orphans/Misc.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ where
1818
import Cardano.Api.Error
1919
import Cardano.Api.Pretty
2020

21+
import Cardano.Chain.Genesis qualified as Byron
2122
import Cardano.Ledger.Alonzo.PParams qualified as Ledger
2223
import Cardano.Ledger.Babbage.PParams qualified as Ledger
2324
import Cardano.Ledger.BaseTypes (strictMaybeToMaybe)
@@ -28,6 +29,7 @@ import Cardano.Ledger.Coin qualified as L
2829
import Cardano.Ledger.Conway.PParams qualified as Ledger
2930
import Cardano.Ledger.HKD (NoUpdate (..))
3031
import Cardano.Ledger.Shelley.PParams qualified as Ledger
32+
import Ouroboros.Consensus.Cardano.Block (EraMismatch (..))
3133
import PlutusLedgerApi.Common qualified as P
3234

3335
import Codec.Binary.Bech32 qualified as Bech32
@@ -36,8 +38,10 @@ import Data.ListMap (ListMap)
3638
import Data.ListMap qualified as ListMap
3739
import Data.Maybe.Strict (StrictMaybe (..))
3840
import Data.Monoid
41+
import Data.Text.Encoding.Error qualified as T
3942
import GHC.Exts (IsList (..))
4043
import Network.Mux qualified as Mux
44+
import Text.Parsec.Error qualified as P
4145

4246
deriving instance Data DecoderError
4347

@@ -270,3 +274,21 @@ instance Error CBOR.DecoderError where
270274

271275
instance Error P.ScriptDecodeError where
272276
prettyError = pshow
277+
278+
instance Error T.UnicodeException where
279+
prettyError = pshow
280+
281+
instance Error EraMismatch where
282+
prettyError (EraMismatch ledgerEraName' otherEraName') =
283+
"The era of the node and the tx do not match. "
284+
<> "The node is running in the "
285+
<> pshow ledgerEraName'
286+
<> " era, but the transaction is for the "
287+
<> pshow otherEraName'
288+
<> " era."
289+
290+
instance Error Byron.GenesisDataGenerationError where
291+
prettyError = pretty . show
292+
293+
instance Error P.ParseError where
294+
prettyError = pretty . show

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ import Cardano.Api.Block
6666
import Cardano.Api.Consensus.Internal.InMode
6767
import Cardano.Api.Consensus.Internal.Mode
6868
import Cardano.Api.Consensus.Internal.Protocol
69+
import Cardano.Api.Error
6970
import Cardano.Api.HasTypeProxy
7071
import Cardano.Api.IO
7172
import Cardano.Api.Monad.Error (ExceptT (..))
7273
import Cardano.Api.Network.IPC.Internal.Version
7374
import Cardano.Api.Network.Internal.NetworkId
75+
import Cardano.Api.Pretty
7476
import Cardano.Api.Query.Internal.Type.QueryInMode
7577
import Cardano.Api.Tx.Internal.Body
7678
import Cardano.Api.Tx.Internal.Sign
@@ -566,6 +568,9 @@ data AcquiringFailure
566568
| AFPointNotOnChain
567569
deriving (Eq, Show)
568570

571+
instance Error AcquiringFailure where
572+
prettyError = pshow
573+
569574
toAcquiringFailure :: Net.Query.AcquireFailure -> AcquiringFailure
570575
toAcquiringFailure AcquireFailurePointTooOld = AFPointTooOld
571576
toAcquiringFailure AcquireFailurePointNotOnChain = AFPointNotOnChain

cardano-api/src/Cardano/Api/Network/IPC/Internal/Version.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ module Cardano.Api.Network.IPC.Internal.Version
77
)
88
where
99

10+
import Cardano.Api.Error
11+
import Cardano.Api.Pretty
12+
1013
import Cardano.Protocol.Crypto
1114
import Ouroboros.Consensus.Cardano.Block qualified as Consensus
1215
import Ouroboros.Consensus.Cardano.Node ()
@@ -52,3 +55,13 @@ data UnsupportedNtcVersionError
5255
![NodeToClientVersion]
5356
-- ^ The versions in which this query is supported
5457
deriving (Eq, Show)
58+
59+
instance Error UnsupportedNtcVersionError where
60+
prettyError (UnsupportedNtcVersionError minNtcVersion ntcVersion) =
61+
"Unsupported feature for the node-to-client protocol version.\n"
62+
<> "This query requires at least "
63+
<> pshow minNtcVersion
64+
<> " but the node negotiated "
65+
<> pshow ntcVersion
66+
<> ".\n"
67+
<> "Later node versions support later protocol versions (but development protocol versions are not enabled in the node by default)."

cardano-api/src/Cardano/Api/Query/Internal/Convenience.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Cardano.Api.Address
2424
import Cardano.Api.Certificate.Internal
2525
import Cardano.Api.Consensus.Internal.Mode
2626
import Cardano.Api.Era
27+
import Cardano.Api.Error
2728
import Cardano.Api.IO
2829
import Cardano.Api.Monad.Error
2930
import Cardano.Api.Network.IPC
@@ -62,6 +63,9 @@ data QueryConvenienceError
6263
| QceUnexpectedException !SomeException
6364
deriving Show
6465

66+
instance Error QueryConvenienceError where
67+
prettyError = pshow . renderQueryConvenienceError
68+
6569
renderQueryConvenienceError :: QueryConvenienceError -> Text
6670
renderQueryConvenienceError (AcqFailure e) =
6771
"Acquiring failure: " <> textShow e

cardano-api/src/Cardano/Api/Serialise/Raw.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ data RawBytesHexError
7474
-- ^ error message
7575
deriving Show
7676

77-
newtype SerialiseAsRawBytesError = SerialiseAsRawBytesError
78-
-- TODO We can do better than use String to carry the error message
79-
{ unSerialiseAsRawBytesError :: String
80-
}
81-
deriving (Eq, Show)
82-
8377
instance Error RawBytesHexError where
8478
prettyError = \case
8579
RawBytesHexErrorBase16DecodeFail input typeRep' message ->
@@ -95,3 +89,12 @@ instance Error RawBytesHexError where
9589
toText bs = case Text.decodeUtf8' bs of
9690
Right t -> Text.unpack t
9791
Left _ -> show bs
92+
93+
newtype SerialiseAsRawBytesError = SerialiseAsRawBytesError
94+
-- TODO We can do better than use String to carry the error message
95+
{ unSerialiseAsRawBytesError :: String
96+
}
97+
deriving (Eq, Show)
98+
99+
instance Error SerialiseAsRawBytesError where
100+
prettyError = pshow . unSerialiseAsRawBytesError

fourmolu.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ sort-deriving-clauses: false
5454
trailing-section-operators: true
5555
unicode: never
5656
respectful: false
57-
fixities: []
57+
fixities:
58+
- infixl 1 &
59+
- infixr 4 .~
5860
reexports: []
5961
local-modules: []

0 commit comments

Comments
 (0)