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

Add proper parsing errors when failing to extract values #1737

Merged
merged 2 commits into from
Jan 7, 2019

Conversation

rgrinberg
Copy link
Member

This helped me debug #1736

@rgrinberg rgrinberg requested review from avsm, emillon, Chris00 and a user January 4, 2019 19:12
@rgrinberg
Copy link
Member Author

@Chris00 feel free to push the fix on top of this PR btw. I'm not entirely sure how the behavior of int_of_string changed since 4.02 so I'm not confident enough to fix this.

The function int_of_string in OCaml 4.02 does not support a leading '+'.

Fixes ocaml#1738

Signed-off-by: Christophe Troestler <[email protected]>
@rgrinberg
Copy link
Member Author

Thanks @Chris00. I tested this out and it seems to work.

I'll let @emillon or @avsm give this an opportunity to review before merging.

Copy link
Member

@avsm avsm left a comment

Choose a reason for hiding this comment

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

Reads fine to me and build-tested on the ocaml-ctypes dune branch.

One observation about the code in stddune is that it uses the option return type rather than Error (Msg of string). In Mirage, we argue that errors should be self-descriptive, but the style in Stddune is that the caller of the option-returning function formats a proper error message. This seems pretty effective as well, but I wonder if gobbling the exception and discarding it in try_with is wise in the longer term... you could still have the "caller-formats-good-errors" discipline with Error return types as well.

@ghost
Copy link

ghost commented Jan 7, 2019

In this case, the exception that is being discarded is Invalid_argument "bool_of_string" which would be of no-use to the user. We could possibly use (t, unit) result rather than t option, to make the failure clearer.

@rgrinberg
Copy link
Member Author

Returning a proper message makes sense when are interested in the modes of failures. Doesn't seem to be the case here.

@rgrinberg rgrinberg merged commit 26803ea into ocaml:master Jan 7, 2019
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.

4 participants