Skip to content
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

Extend deserialiseFromRawBytesHex to produce error description #3304

Merged
merged 3 commits into from May 2, 2022

Conversation

cblp
Copy link
Contributor

@cblp cblp commented Oct 20, 2021

No description provided.

Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, let's reorganize these commits:
Commit 1: Change to deserialiseFromRawBytesHex
Commit 2: Propagating this change throughout the repo
Commit 3: Miscellaneous refactorings

@cblp cblp force-pushed the cblp/deserialiseFromRawBytesHex branch from 2f8a9a7 to 0c449a8 Compare December 23, 2021 15:24
@cblp cblp requested a review from Jimbo4350 December 23, 2021 15:24
@cblp
Copy link
Contributor Author

cblp commented Dec 23, 2021

Right, let's reorganize these commits: Commit 1: Change to deserialiseFromRawBytesHex Commit 2: Propagating this change throughout the repo Commit 3: Miscellaneous refactorings

done

@cblp cblp force-pushed the cblp/deserialiseFromRawBytesHex branch from 0c449a8 to 602084e Compare December 24, 2021 14:18
Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right direction, a few comments

case Base16.decode hex of
Right raw -> deserialiseFromRawBytes proxy raw
Left _msg -> Nothing
=> AsType a -> ByteString -> Either String a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String isn't a particularly indicative error type. We should create a custom datatype, for example:

data RawBytesHexError = RawBytesHexErrorBase16DecodeFail ByteString String | RawBytesHexErrorRawBytesDecodeFail ByteString String

We can also implement an Error instance to render the errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be done in another patch. String is used already everywhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String is used already everywhere.

And it shouldn't be. Even more reason to change the error type.

cardano-api/src/Cardano/Api/Utils.hs Outdated Show resolved Hide resolved
cardano-cli/src/Cardano/CLI/Helpers.hs Outdated Show resolved Hide resolved
@cblp cblp force-pushed the cblp/deserialiseFromRawBytesHex branch 2 times, most recently from 5d6bc07 to 039952d Compare January 11, 2022 17:04
@cblp cblp requested a review from Jimbo4350 January 11, 2022 17:05
@cblp cblp force-pushed the cblp/deserialiseFromRawBytesHex branch 4 times, most recently from 994a333 to 6e9ecac Compare January 21, 2022 13:56
@cblp cblp force-pushed the cblp/deserialiseFromRawBytesHex branch from 3911a12 to 8ce6b0f Compare March 14, 2022 16:59
@cblp cblp force-pushed the cblp/deserialiseFromRawBytesHex branch from 8ce6b0f to 5dacedb Compare March 23, 2022 16:52
@cblp
Copy link
Contributor Author

cblp commented Mar 24, 2022

bors merge

iohk-bors bot added a commit that referenced this pull request Mar 24, 2022
3304: Extend deserialiseFromRawBytesHex to produce error description r=cblp a=cblp



Co-authored-by: Yuriy Syrovetskiy <yuriy.syrovetskiy@iohk.io>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Mar 24, 2022

Build failed:

@cblp cblp force-pushed the cblp/deserialiseFromRawBytesHex branch 2 times, most recently from 64dd0ec to 7c4093e Compare March 25, 2022 16:22
@cblp cblp force-pushed the cblp/deserialiseFromRawBytesHex branch 2 times, most recently from 2337440 to f8835a0 Compare April 15, 2022 15:05
@cblp cblp force-pushed the cblp/deserialiseFromRawBytesHex branch 2 times, most recently from 94c2835 to 87645b3 Compare April 20, 2022 15:43
@cblp
Copy link
Contributor Author

cblp commented Apr 22, 2022

bors merge

iohk-bors bot added a commit that referenced this pull request Apr 22, 2022
3304: Extend deserialiseFromRawBytesHex to produce error description r=cblp a=cblp



Co-authored-by: Yuriy Syrovetskiy <yuriy.syrovetskiy@iohk.io>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Apr 22, 2022

This PR was included in a batch that successfully built, but then failed to merge into master. It will not be retried.

Additional information:

{"message":"Waiting on code owner review from MarcFontaine, cleverca22, deepfire, denisshevchenko, and/or jutaro.","documentation_url":"https://docs.github.com/articles/about-protected-branches"}

@cblp
Copy link
Contributor Author

cblp commented Apr 27, 2022

bors merge

iohk-bors bot added a commit that referenced this pull request Apr 27, 2022
3304: Extend deserialiseFromRawBytesHex to produce error description r=cblp a=cblp



Co-authored-by: Yuriy Syrovetskiy <yuriy.syrovetskiy@iohk.io>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Apr 27, 2022

This PR was included in a batch that successfully built, but then failed to merge into master. It will not be retried.

Additional information:

{"message":"Waiting on code owner review from MarcFontaine, cleverca22, deepfire, denisshevchenko, and/or jutaro.","documentation_url":"https://docs.github.com/articles/about-protected-branches"}

data RawBytesHexError
= RawBytesHexErrorBase16DecodeFail
ByteString -- ^ original input
String -- ^ error message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not do better than a String here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry? Too much indirection for my English.

Do you suggest having something more structured than a String in the second field of RawBytesHexErrorBase16DecodeFail or not?

cardano-api/src/Cardano/Api/Script.hs Outdated Show resolved Hide resolved
case deserialiseFromRawBytesHex AsTxId (BSC.pack str) of
Just addr -> return addr
Nothing -> fail $ "Incorrect transaction id format:: " ++ show str
str <- some Parsec.hexDigit <?> "transaction id (hexadecimal)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a reason to switch many1 to some? The Parsec version has an implementation specialised to parsers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some is a less surprising name for the same thing.

@@ -1974,7 +1975,7 @@ parseTxIn = TxIn <$> parseTxId <*> (Parsec.char '#' *> parseTxIx)

parseTxId :: Parsec.Parser TxId
parseTxId = do
str <- Parsec.many1 Parsec.hexDigit Parsec.<?> "transaction id (hexadecimal)"
str <- some Parsec.hexDigit <?> "transaction id (hexadecimal)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question. Is this change needed? Why?

Copy link
Contributor

@MarcFontaine MarcFontaine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM concerning the tx-generator

@cblp cblp force-pushed the cblp/deserialiseFromRawBytesHex branch from 87645b3 to beae391 Compare April 29, 2022 16:43
@cblp
Copy link
Contributor Author

cblp commented May 2, 2022

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented May 2, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit 567ee70 into master May 2, 2022
@iohk-bors iohk-bors bot deleted the cblp/deserialiseFromRawBytesHex branch May 2, 2022 16:16
@cblp cblp moved this from Review to Merged in cardano-node/cardano-api/cardano-cli May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants