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

Use Core.Error.tag/tag_arg when adding info to errors #6699

Closed
mrmr1993 opened this issue Nov 13, 2020 · 0 comments · Fixed by #6751
Closed

Use Core.Error.tag/tag_arg when adding info to errors #6699

mrmr1993 opened this issue Nov 13, 2020 · 0 comments · Fixed by #6751
Assignees
Labels

Comments

@mrmr1993
Copy link
Member

Currently, we do a variety of different things to create an error with additional information out of an Error.t. Most of these involve converting the Error.t to a string with Error.to_string_hum and then creating a new exception with failwithf, Error.createf, Error.of_string, etc. This way, we end up with errors which are s-expressions encoded as strings in s-expressions encoded as strings etc.

For example, in coda_net2 we have

      failwithf "unexpected error doing setGatingConfig: %s"
        (Error.to_string_hum e) ()

Core has functions Error.tag : Error.t -> tag:string -> Error.t and Error.tag_arg : Error.t -> string -> 'a -> ('a -> Sexp.t) -> Error.t designed for adding this information without disrupting or string-encoding the underlying data. These are designed for this purpose, and we should use them!

The above example could easily be changed to

Error.raise (Error.tag ~tag:"unexpected error doing setGatingConfig" e)

This has the added advantage of working nicely with #6698, which will accumulate these tags and print them as part of the JSON metadata that we log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants