-
Notifications
You must be signed in to change notification settings - Fork 205
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 support for returning and handling errors #7
Comments
This was my first instinct as well. But I also have to be honest, I've been spending my evenings exploring what it would look like to use our own custom variant of an IDL rather than just relying on what's available in WebIDL...which might come to nothing or might change how we want to proceed here. We should not block on that though :-)
I think we need some structure, e.g. in the fxa-client the kotlin code needs to be able to distinguish between a network error and a hard failure. Strawman: |
I'm thinking of taking a look at this, but before I go in over my head, I wanted to dump my thought process in case I have something off (or maybe there are blockers I haven't thought about or something) The WebIDL would look something like this:enum Error {
"NETWORK_ERROR", "TYPE_ERROR"
};
interface InterfaceName {
constructor();
[Throws(Error)]
string func();
};
This should give us all the information needed to form the scaffolding and the bindings (right?) Edit: Guess we'd need to add the same From the scaffolding side
BindingsEach binding will be different but the concept is the same
Haven't really looked at the details here and it might be painful, but if the details of the error are in the Thoughts? Anything large I miss? Or is there a different path you'd rather we go with? Any feedback is welcome! |
That sounds perfect! 💯 On the Rust side, we can use the Swift has fallible functions, methods and constructors; plumbing the |
Thanks @linacambridge!! For
I was playing around and one thing I tried is to let the consumer define their own Rust
I guess it's a matter of flexibility vs if we want the consumer to know about Anywhoo, I'll put up my |
FWIW, in general I like the principal that you should be able to look at the rust code and understand in isolation as plain old rust code, without having to understand the extra things that will get magicked into existence by the scaffolding. I think that aligns broadly with what you describe above - the user defines an (I haven't looked at your PR yet, that's purely an idea-level reaction based on what you describe above).
We could use an attribute, or we could infer which enums are errors by walking the set of all functions/methods and mark anything that gets thrown as being an error enum. (If we do use an attribute, we'll have to do the opposite check and ensure that anything things marked with the attribute are thrown).
Yep, which IIUC is similar to the current restrictions on non-error enums between Rust and the IDL. One of the advantages of this philosophy I think, is that it keeps open the open of moving from a separate IDL to some inline definitions based on macros. |
We have lots of
TODO
s for adding error handling. A few things we’ll want to think about:Result
return values? Following how Firefox does it, using aThrows
annotation on fallible methods? Do we want to have structured errors that can be inspected, or are error strings good enough?throws
keyword to indicate a function is fallible, and Kotlin and Python functions can throw exceptions. We will need to teach our code generation layer to reflect error results as exceptions.┆Issue is synchronized with this Jira Task
The text was updated successfully, but these errors were encountered: