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

No way to access stdweb's ConversionError #39

Closed
ASalvail opened this issue Sep 14, 2018 · 4 comments
Closed

No way to access stdweb's ConversionError #39

ASalvail opened this issue Sep 14, 2018 · 4 comments

Comments

@ASalvail
Copy link
Collaborator

Most of stdweb conversion return a ConversionError when it fails. The problem with this is that the struct is kept private. Admittedly, it is exposed (but hidden) through stdweb::private, however, this is not really a fix as we would still have problems with associated types not resolving to concrete types.

My suggestion would be to define a ConversionError owned by out lib that would box over stdweb's own ConversionError. This would remove a lot of headaches due to associated type.

@daboross
Copy link
Collaborator

For some of the situations it might be possible to create our own type alias without wrapping stdweb::webcore::ConversionError, something like:

pub type ConversionError = <i32 as TryFrom<Value>>::Error

@ASalvail
Copy link
Collaborator Author

We could simplify a lot I suppose by returning a trait object implementing std::error::Error and just be done with it...
My problems now are:

  • I can't construct the ConversionError (have to do my checks in JS)
  • I can't append another, let's say, ReferenceError without dropping or boxing the ConversionError.
  • It's generally a pain to work with the associated types.

@daboross
Copy link
Collaborator

Ah, hm. I hadn't thought of the possibility of doing checks outside of JS.

One thing that might help here is stdweb_derive's #[derive(ReferenceType)]. It might be able to do checks for us if we #[derive(ReferenceType)] #[reference(instance_of = "Creep")] - I vague remember explicitly not choosing to use this since it did checks, but if we have a way to construct the value outside of TryFrom it might be more reasonable. Have you looked at this at all, and do you think it might alleviate the pain of working with ConversionError by it just doing everything?

Above might be a bit off-topic, but I don't know if we have a particularly on-topic issue for discussing this.

@daboross
Copy link
Collaborator

CC koute/stdweb#280.

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

No branches or pull requests

2 participants