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

Improve documentation and error handing for --code-a/--code-b #583

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

msooseth
Copy link
Collaborator

@msooseth msooseth commented Oct 7, 2024

Description

As per #581 the error printing was wrong. Furthermore, we should have examples on HOW to paste in text from files. It was not obvious to me how to do it, so we should have at least one example in our handbook.

Checklist

  • tested locally
  • added automated tests
  • updated the docs
  • updated the changelog

@msooseth msooseth requested a review from blishko October 7, 2024 12:39
@charles-cooper
Copy link

looks good, although maybe this should be a validation error instead of an internal error?

@msooseth
Copy link
Collaborator Author

msooseth commented Oct 7, 2024

Good point actually! I have now changed it so it gives us a normal error:

$ cabal run -f devel exe:hevm -- equivalence --code-a <(cat a.txt) --code-b <(cat b.txt)
hevm: Invalid hex bytestring provided for '--code'. Bytestring provided: '"/proc/self/fd/13"'
CallStack (from HasCallStack):
  error, called at src/EVM/Format.hs:831:10 in hevm-0.53.0-inplace:EVM.Format

I hope this is better!

@@ -828,7 +828,7 @@ hexByteString :: String -> ByteString -> ByteString
hexByteString msg bs =
case BS16.decodeBase16Untyped bs of
Right x -> x
_ -> internalError $ "invalid hex bytestring for " ++ msg
_ -> error $ "Invalid hex bytestring provided for '" ++ msg ++ "'. Bytestring provided: '" ++ show bs ++ "'"
Copy link
Collaborator

Choose a reason for hiding this comment

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

this change is a clear upgrade to existing code so totally fine for now, but just a general comment not a great ux to use error for user facing errors, and this function might be better written to return an Either (or perhaps we could add some special Error effect to Effects.hs?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, actually, good point. It should be an Either. I'll rewrite it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, I have re-written the error handling here to be MUCH better. It's done with Maybe and we handle the errors at the source when the Nothing happens, and give very user-friendly error messages, with exitFailure, etc. @d-xo let me know what you think!

@charles-cooper
Copy link

Out of scope for this PR I think but it might be convenient to be able to do hevm equivalence a.txt b.txt (and maybe even more than two files!)

@msooseth msooseth force-pushed the fix-print-better-example branch 2 times, most recently from a1fc1d0 to 89771a2 Compare October 10, 2024 15:52
@msooseth msooseth force-pushed the fix-print-better-example branch from 57d6e2b to e76e4f6 Compare October 22, 2024 09:42
…dling

Also giving example for how to do equivalence checking
@msooseth msooseth force-pushed the fix-print-better-example branch from e76e4f6 to f01005c Compare October 22, 2024 13:06
@msooseth msooseth merged commit 924e653 into main Oct 22, 2024
8 of 9 checks passed
@msooseth msooseth deleted the fix-print-better-example branch October 24, 2024 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants