-
Notifications
You must be signed in to change notification settings - Fork 43
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
Producing Errors for JS in Class Constructor #141
Comments
There are 2 approaches I can think of:
However, we need to fix procedure macro to accept Second approach is allow constructor to return Result and have procedure macro to generate Error conversion.
|
So the second option seems like the better of the two in my case. This is because it seems that in the event of an error, the construction would produce the Error result instead of an instance with some arbitrary "null-like" value, which wouldn't be clean to implement in a case where you had some, say complex object in the struct like say a File or something. So then my further question because I'm not exactly sure what you mean, what would the procedure macro to "generate Error conversion" look like? what would its objective be? And what would be a good resource for me to understand how that would be done, like I said I'm somewhat new at rust? |
I think #155 simplifies the issues @NovaLogicDev has had - now structs and enums to-js conversions can be autoderived. Also structured errors can be returned from
should work and throw |
@sehz is this supposed to work now with v5? I mean is a constructor supported that returns a |
@marcmo current release is 5.1.0. So should work. please check |
This doesn't work on the latest release
with the constructor being defined as #[node_bindgen]
impl IrohNode {
#[node_bindgen(constructor)]
pub fn new_js() -> Result<Self, Error> {
// .. actual logic
}
} |
@ozgrakkurt triage |
trivially
This example causes the JS application to crash completely if the function returns an error, which would be great if that's what I wanted, but instead, I would like to be able to have the constructor error out, producing an error to be caught by JS instead of returning Self.
Now I'm newish to rust so maybe I missed something but the only way I understand to get an error up the call stack is to keep returning Results, however
#[node_bindgen(constructor)]
only accepts a return of "Self
."Understandably it could be possible to make
a_string
typeResult
, however, I would have to check it in every function and that simply causes problems for certain more complex objects that I intend to use.So I am here to ask, how do I throw errors for catching in JS from my struct "constructor"?
The text was updated successfully, but these errors were encountered: