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

error safety #11

Open
dherman opened this issue Nov 22, 2017 · 2 comments
Open

error safety #11

dherman opened this issue Nov 22, 2017 · 2 comments

Comments

@dherman
Copy link
Contributor

dherman commented Nov 22, 2017

We need to spell out our approach to error safety. This has come up in a few issues on the main repo:

@nixpulvis
Copy link

I think as a general rule of thumb, any possibility to "catch" JS exceptions and return Results should be used. This is in many ways one of the main promises of this library to me.

@kjvalencik
Copy link
Member

I don't think the API should do a throw for expected failures. E.g., check and require should return Result instead of performing a JsError::throw.

It could follow the error_chain idiom and convert the errors to exceptions as part of the export macro.

pub fn check<U: Value>(&self) -> Result<'a, U> {
	U::downcast(self.value)
		.chain_err(|| ErrorKind::TypeError("type error".to_string()))
}

/* ... */

wrapped_method(call).map_err(|e| match e {
	e @ Error(ErrorKind::TypeError(_), _) => /* something like this? */
})

This may require modeling exceptions as panic to prevent mixing recoverable and unrecoverable result types.

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

3 participants