-
Notifications
You must be signed in to change notification settings - Fork 36
Improve token-metadata-creator error messages #27
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
Conversation
sevanspowell
commented
May 18, 2021
- As per Testing decimals #26, improve error messages when failing to parse a decimals value.
- For well-known properties, we may be wanted to parse a String or some other type. I've improved the error messages by first trying to parse as an arbitrary JSON value, and it that fails with some "not a valid json value"-style errors, try to parse as a string.
- It's only a quick fix, but it does provide better results:
rvl
left a comment
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.
Looks like it will work. 👍
piotr-iohk
left a comment
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.
LGTM.
Thanks @sevanspowell!
BTW, do you have any clue why this other npm tests that I mentioned in #26 fails?
1 failing
1) token-metadata-creator
Minimal workflow
Add required fields:
AssertionError: expected { Object (sequenceNumber, value, ...) } to deeply equal { Object (sequenceNumber, signatures, ...) }
+ expected - actual
{
"sequenceNumber": 0
"signatures": []
- "value": "������"
+ "value": "ギル"
}
I think this used to work before 🤔
|
I suspect it's a genuine failure because of the change to string parsing on the CLI. |
|
Hmm, I ran those test locally and they all passed so I assumed they worked. Let me double check for you. |
bb3c28e to
f7d5b7b
Compare
Confirmed @piotr-iohk, those npm/nodejs tests complete successfully 👍 |
|
Try reproducing it this way: |
rvl
left a comment
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.
Here's an approximate fix for the test failure.
| asJSONString :: String -> Either String p | ||
| asJSONString = Aeson.parseEither parseWellKnown . Aeson.String . T.pack |
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.
| asJSONString :: String -> Either String p | |
| asJSONString = Aeson.parseEither parseWellKnown . Aeson.String . T.pack | |
| asJSONString :: ByteString -> Either String p | |
| asJSONString = (Aeson.parseEither parseWellKnown . bimap show Aeson.String) <=< T.decodeUtf8' |
Use Data.Text.Encoding.decodeUtf8' to ensure that text is always treated as UTF-8.
| asJSONValue :: String -> Either String p | ||
| asJSONValue = (Aeson.parseEither parseWellKnown =<<) . Aeson.eitherDecodeStrict' . BC8.pack |
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.
| asJSONValue :: String -> Either String p | |
| asJSONValue = (Aeson.parseEither parseWellKnown =<<) . Aeson.eitherDecodeStrict' . BC8.pack | |
| asJSONValue :: ByteString -> Either String p | |
| asJSONValue = Aeson.parseEither parseWellKnown <=< Aeson.eitherDecodeStrict' |
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.
Hmm, that solution just moves the decoding error to the UTF-8 locale. The C locale works, but UTF-8 throws the same error. I'll look into the character encoding a bit more, I imagine I'm going to have to normalize the input stream.
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.
Which is exactly what you were saying... Sorry.
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.
No prob!
f7d5b7b to
c3aacda
Compare
|
I added the utf-8 locale fix that we have in cardano-wallet. |
c3aacda to
61a4ab8
Compare
|
@rvl @sevanspowell this is something I'm also able to reproduce manually. My default bash locale is: (so, I guess, nothing fancy) Doing: results in this in the *.json.draft: |
|
@piotr-iohk is that with the changes @rvl committed a few minutes ago (61a4ab8)? I've just tested it myself with my bash locale the same as yours, but it worked for me. |
|
Ah yes @piotr-iohk - good catch - I found there was something else missing in the locale-setting code. |
|
@sevanspowell @rvl yes I was checking just before latest commits. |
2661: CLI: Force command-line arguments to be UTF-8 decoded r=rvl a=rvl ### Issue Number Bug found while doing ADP-915. ### Overview Applies the same fix as in input-output-hk/offchain-metadata-tools#27 so that command-line arguments are also decoded as UTF-8 text, regardless of the user's locale setting. 2664: Fix slow ApiSharedWallet unit tests r=rvl a=rvl ### Issue Number Found during ADP-902 ### Overview The `Cardano.Wallet.Api.Types` tests are running very slowly. Also the unit tests were sometimes timing out in CI. Profiling showed that the `Arbitrary` instance of `ApiSharedWallet` was the slowest part. This change improves the speed of this generator. Now it is the OpenAPI validation which is the slowest part. ### Comments We may also be able to reduce the size of arbitrary `ApiSharedWallet` values, so that validation gets faster. Because it's still not especially quick. Something like the `instance Arbitrary WalletName` change in this PR could probably be applied. Co-authored-by: Rodney Lorrimar <[email protected]>