-
Notifications
You must be signed in to change notification settings - Fork 720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved error message for failed asset name decode #4626
Improved error message for failed asset name decode #4626
Conversation
Notes: The protocol parameters were obtained like this:
|
c24782d
to
7531c4d
Compare
@@ -26,6 +26,9 @@ class (HasTypeProxy a, Typeable a) => SerialiseAsRawBytes a where | |||
serialiseToRawBytes :: a -> ByteString | |||
|
|||
deserialiseFromRawBytes :: AsType a -> ByteString -> Maybe a | |||
deserialiseFromRawBytes asType bs = rightToMaybe $ eitherDeserialiseFromRawBytes asType bs | |||
|
|||
eitherDeserialiseFromRawBytes :: AsType a -> ByteString -> Either String a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New method eitherDeserialiseFromRawBytes
. Old method deserialiseFromRawBytes
delegates to this.
7531c4d
to
acf4941
Compare
Much better! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good so far but a few comments
let lBs = LB.fromStrict bs | ||
in case Binary.decodeFull lBs of | ||
Left _deserFail -> Nothing | ||
Right proposal -> Just (ByronUpdateProposal proposal') | ||
Left e -> Left $ "Unable to deserialise ByronUpdateProposal: " <> show e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to (more easily) maintain consistency in the errors what do you think about the following:
...
eitherDeserialiseFromRawBytes
:: AsType a -> ByteString -> Either (SerialiseAsRawBytesError (AsType a)) a
data SerialiseAsRawBytesError a = SerialiseAsRawBytesError a
instance Error (SerialiseAsRawBytesError a) where
displayError (SerialiseAsRawBytesError a) = "Unable to deserialise " <> show a
Example usage:
...
eitherDeserialiseFromRawBytes AsScriptHash bs =
maybeToRight (SerialiseAsRawBytesError AsScriptHash) $
ScriptHash . Shelley.ScriptHash <$> Crypto.hashFromBytes bs
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could potentially also include the original ByteString
in the SerialiseAsRawBytesError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we did this we would only have one error value per AsType
, so we couldn't have more than one kind of serialisation error per type. If deserialisation could fail in more than one way depending on what is in the byte string we would be unable to communicate to the user that distinction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the moment, I created a new type SerialiseAsRawBytesError
which is just a wrapper around String
whilst waiting for further feedback.
c26831a
to
02ea740
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, few minor comments. Please squash the last two commits.
02ea740
to
ade7df0
Compare
ade7df0
to
7fedaa4
Compare
7fedaa4
to
f034ded
Compare
bors r+ |
4626: Improved error message for failed asset name decode r=newhoggy a=newhoggy The new error message can be seen in this output: ``` cardano-cli transaction calculate-min-required-utxo --protocol-params-file ../protocol-params.json --babbage-era --tx-out "addr1q9h2kw7neeh26cmhspye2gyvhca6qaqxakp7qcp3uydzphqu62gur507vnszr24dyt2z6lrmpmrufs6jjdhc2vy04hzqyuuw8z+1 ee659e0a80e8a9815afe8aa3906741c34d234923f4da0543ec1628d4.5468654D616E6472696C6C7A576F726C6443757045646974696F6E233335302337" option --tx-out: unexpected end of input expecting hexadecimal digit AssetName deserisalisation failed: Failed to deserialise 5468654D616E6472696C6C7A576F726C6443757045646974696F6E233335302337 as AssetName. Unable to deserialise AssetName (the bytestring should be no longer than 32 bytes long which corresponds to a hex representation of 64 characters) Usage: cardano-cli transaction calculate-min-required-utxo [ --byron-era | --shelley-era | --allegra-era | --mary-era | --alonzo-era | --babbage-era ] (--genesis FILE | --protocol-params-file FILE) --tx-out ADDRESS VALUE [ --tx-out-datum-hash HASH | --tx-out-datum-hash-cbor-file CBOR FILE | --tx-out-datum-hash-file JSON FILE | --tx-out-datum-hash-value JSON VALUE | --tx-out-datum-embed-cbor-file CBOR FILE | --tx-out-datum-embed-file JSON FILE | --tx-out-datum-embed-value JSON VALUE | --tx-out-inline-datum-cbor-file CBOR FILE | --tx-out-inline-datum-file JSON FILE | --tx-out-inline-datum-value JSON VALUE ] [--tx-out-reference-script-file FILE] Calculate the minimum required UTxO for a transaction output. ``` Resolves #4619 Co-authored-by: John Ky <[email protected]>
Timed out. |
f59bda4
to
9b9df9b
Compare
…class More descriptive error message for decode of AssetName Introduce new SerialiseAsRawBytesError error type
9b9df9b
to
1246771
Compare
The new error message can be seen in this output:
Resolves #4619