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
Ways to better integrate JS and OCaml exceptions into Relude IO #259
Comments
I'm not even 100% this would be worth it, since right now I'm just wrapping functions like this in a This approach would just let me centralize the error logic in one place instead of scattered in throughout the code base. But not sure, just throwing out ideas. EDIT: Actually, having tried this out in our codebase, this is pretty useful. It allows me to centralize the error handling in one place in all our IO code, instead of having a bunch of It's possible I'm misusing, or not understanding, the existing I'll definitely use the approach above in our IO code, unless I'm misunderstanding how to integrate I haven't looked closely at the |
I think the general pattern for synchronous calls would be to use
For async code, there is I'm not sure if we need the different arities of I could see an argument for a version of
These would provide an error handling function rather than having to do the Is this what you're thinking? |
I'm going to close this for inactivity. I'm not sure if anything should be done here, or if it's more of a discussion. Feel free to re-open if more discussion is desirable. |
I've been thinking about ways to better integrate legacy code and code that wraps JS APIs, both of which can throw OCaml and JS exceptions, into code using Relude IO.
If there's a good way right now to do so, pls let me know, but if not: one possibility, although the API is a bit complex, is to offer an IO function that takes a function capable of converting a JS or OCaml exception, its parameter(s), and a function that converts the exception(s) into a custom IO error type.
It's just an expansion on the existing
IO.tries
andIO.triesJS
, but can be integrated into other Relude IO since the type isRelude.IO.t('a, 'e)
instead ofRelude.IO.t('a, exn)
. So you'd end up with something like this:The text was updated successfully, but these errors were encountered: