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

create Error instances in cordova api #140

Open
ecioppettini opened this issue Mar 4, 2021 · 1 comment
Open

create Error instances in cordova api #140

ecioppettini opened this issue Mar 4, 2021 · 1 comment
Labels
bindings - cordova enhancement New feature or request

Comments

@ecioppettini
Copy link
Contributor

Currently we are throwing errors to cordova that are the text descriptions of the errors (e.g.

Self::InvalidInput { argument_name } => {
)

This keeps the cordova code simple, in a way, and it's fine for developing/testing, but not so much for handling production-time errors.

I think the proper way would be to extend javascript Error with custom instances, the problematic thing about this is that it requires that we define them manually in javascript, and keep them in sync with the C-level ones (or just have two different things).

I'm still not sure, what's the best way to tackle this though.

One option could be to change jni and objective-c code to return error pointers instead of strings, then do catch that ourselves at the plugin level, and make another cordova/abi roundtrip in javascript to extract the error description, name, error description, etc. And then deallocate the error.

Also, the other problem is that making this right probably requires doing the same for wallet-jni with java Exception extensions or something, although this makes things harder.

The other problem is that the browser/electron implementations don't even use the c error types, although no one is using this platforms anyway.

@mzabaluev
Copy link
Contributor

It would be good to expose the error code:

In JavaScript, the error object could have a code member with this integer code in addition to the message.
For discrimination, the JavaScript API may define named constants for the error codes, matching the definitions on the Rust side.

Also, the other problem is that making this right probably requires doing the same for wallet-jni with java Exception extensions or something

How about wallet-jni defines an application domain exception class which features the same code in the idiomatic Java way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bindings - cordova enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants