@@ -227,7 +227,10 @@ bodyError = BodyError . Text.pack . C.docToString . C.prettyError
227
227
228
228
$ (deriveFromJSON defaultOptions{sumEncoding = TaggedObject {tagFieldName = " kind" , contentsFieldName = " value" }} ''C. ScriptWitnessIndex )
229
229
230
- -- | Balancing errors, including the *special* 'BalancingScriptExecutionErr'.
230
+ {- | Balancing errors, including the important 'ScriptExecutionErr'. "Important" in the sense that we
231
+ can write prisms such as 'exactScriptExecutionError' that allow for more fine-grained
232
+ pattern-matching on the on-chain error.
233
+ -}
231
234
data BalancingError era
232
235
= BalancingError Text
233
236
| -- | A single type of balancing error is treated specially: the type with
@@ -243,10 +246,10 @@ data BalancingError era
243
246
244
247
makeClassyPrisms ''BalancingError
245
248
246
- {- | This prism will either match on the exact error using the script witness index and an error
247
- string, or just on being a script execution error. The latter is necessary, since in non- debug
248
- mode, there is no error to match on and the prism should not fail in its purpose in non-debug
249
- mode.
249
+ {- | This prism will match on the exact error using the script witness index and an error
250
+ string if this information is available. It will behave as a script execution error if no debug logs
251
+ are available. The latter is necessary, since in non-debug mode, there is no error to match on and
252
+ the prism should not fail in its purpose in non-debug mode.
250
253
-}
251
254
exactScriptExecutionError :: forall e era . (AsBalancingError e era ) => (Int , Text ) -> Prism' e [(C. ScriptWitnessIndex , Text , [Text ])]
252
255
exactScriptExecutionError (i, s) = prism' tobe frombe
@@ -267,8 +270,12 @@ exactScriptExecutionError (i, s) = prism' tobe frombe
267
270
-- Not the correct error
268
271
| otherwise -> Nothing
269
272
270
- {- | Sort *most* balancing errors into 'BalancingError', but script execution errors into their own
271
- data constructor.
273
+ {- | This convenience function takes @Left@s of type 'C.TxBodyErrorAutoBalance' and throws
274
+ 'C.TxBodyScriptErecutionError's as 'ScriptExecutionErr', with extraaction of the error log, if
275
+ availalbe. Other @Left@s are thrown as 'BalancingError's.
276
+
277
+ This is a convenient bridge from cardano-api errors to errors where we can pattern-match on script
278
+ execution errors and have an error hierarchy.
272
279
-}
273
280
balancingError :: (MonadError (BalancingError era ) m ) => Either (C. TxBodyErrorAutoBalance era ) a -> m a
274
281
balancingError = \ case
0 commit comments