Skip to content

Error handling with failure (using Error and ErrorKind)#713

Merged
antiochp merged 10 commits into
mimblewimble:masterfrom
cyclefortytwo:try-failure
Feb 28, 2018
Merged

Error handling with failure (using Error and ErrorKind)#713
antiochp merged 10 commits into
mimblewimble:masterfrom
cyclefortytwo:try-failure

Conversation

@hashmap

@hashmap hashmap commented Feb 16, 2018

Copy link
Copy Markdown
Contributor

This PR adresses #166

We explored two approaches:

This PR illustrate the second approach in the wallet code, see a separate PR for the first one. This approach changes a lot in error handling but potentially is more flexible. It allows n:m mapping of underlying errors to the wallet errors.

This is work in progress, the code can't be merged or even compiled (2 errors outside wallet module) we'd like to get some initial feedback before investing more efforts into it.

@ignopeverell

Copy link
Copy Markdown
Contributor

I would favor this over #712 but would like to hear what @antiochp, @yeastplume and @quentinlesceller would have to say as well.

Sorry for the stupid question, I'm not familiar with failure (yet) and the docs weren't really explicit: how does one specify whether a failure captures its stacktrace?

@hashmap

hashmap commented Feb 16, 2018

Copy link
Copy Markdown
Contributor Author

@ignopeverell I agree, this approach is more promising but requires more efforts. The author of failure mentioned that it could be (more) automated in the future.

There is no such thing as stupid question. It follows the panic convention - if RUST_BACKTRACE is set a stacktrace will be generated https://boats.gitlab.io/failure/fail.html#backtraces

@hashmap

hashmap commented Feb 16, 2018

Copy link
Copy Markdown
Contributor Author

Forgot to mention that we had to implement sstd::error::Error for errors in keychain and transaction. It's temporary solution until it's converted to failure.

Comment thread wallet/src/client.rs

fn single_send_partial_tx(url: &str, partial_tx: &PartialTx) -> Result<PartialTx, Error> {
let mut core = reactor::Core::new()?;
let mut core = reactor::Core::new().context(ErrorKind::Hyper)?;

This comment was marked as spam.

Comment thread wallet/src/types.rs
fn from(e: hyper::Error) -> Error {
Error::Hyper(e)
}
impl From<ErrorKind> for Error {

This comment was marked as spam.

Comment thread wallet/src/types.rs
"Could not remove wallet lock file. Maybe insufficient rights?"
))
})?;
fs::remove_file(lock_file_path).context(ErrorKind::WalletData("Could not remove wallet lock file. Maybe insufficient rights?"))?;

This comment was marked as spam.

@antiochp antiochp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this makes sense.
I suspect this is something we would need to use for a while before fully understanding the benefits...
👍

@hashmap

hashmap commented Feb 18, 2018

Copy link
Copy Markdown
Contributor Author

Thanks for nice and helpful feedback. Merged with the current master. We will check couple of places where .map_err() is still used. Need some help with verifying context in each case, could be incorrect.

@hashmap hashmap changed the title [WIP] Error handling with failure (using Error and ErrorKind) Error handling with failure (using Error and ErrorKind) Feb 20, 2018
@hashmap

hashmap commented Feb 20, 2018

Copy link
Copy Markdown
Contributor Author

It's ready for review.

@antiochp antiochp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I like this.

@antiochp

Copy link
Copy Markdown
Member

@hashmap looks like there are some conflicts to clean up.
Lets get this merged in if @ignopeverell and @yeastplume are happy with this approach.

@yeastplume

Copy link
Copy Markdown
Member

seems to makes sense, very much in favour of centralising error handling code better and even though this looks a bit boilerplate heavy to set up, it looks like it will ultimately make error handling easier to follow.. will be much better informed after trying to use it properly for a while, but I’m okay giving this approach a try

@antiochp

Copy link
Copy Markdown
Member

Sounds like everyone is on board? I'm going to go ahead and merge.

@antiochp antiochp merged commit 9e11afe into mimblewimble:master Feb 28, 2018
@heunglee

heunglee commented Mar 16, 2018

Copy link
Copy Markdown
Contributor

While I am working on taking iron out of wallet lib, I noticed the changes on error handling. Using failure::Fail in wallet seems not fully embraced by Api library yet with respect to client/server error handling. At this moment, I map Api::Error into Http response:
Error::Argument -> Http::StatusCode::BadRequest
Error::Internal -> Http::StatusCode::InternalServerError
Error::NotFound -> Http::StatusCode::NotFound
and vise versa on the client side.

Sine I am not familiar with failure, I am not sure how to map Fail(e) on coinbase handler in wallet into Http status code. e is of Api::Error. So for now, I will comment the part for later visit and just map e into http status code. Any opinion and thoughts?

@hashmap

hashmap commented Mar 22, 2018

Copy link
Copy Markdown
Contributor Author

hashmap added a commit to cyclefortytwo/grin that referenced this pull request Apr 6, 2018
This PR adresses mimblewimble#166
Error handling in wallet was ported to failure in mimblewimble#713
Using the same error model makes wallet code simpler and may simplify migration to Hyper.
hashmap added a commit to cyclefortytwo/grin that referenced this pull request Apr 6, 2018
This PR adresses mimblewimble#166
Error handling in wallet was ported to failure in mimblewimble#713
Using the same error model makes wallet code simpler and may simplify migration to Hyper.
hashmap added a commit to cyclefortytwo/grin that referenced this pull request Apr 9, 2018
This PR adresses mimblewimble#166
Error handling in wallet was ported to failure in mimblewimble#713
Using the same error model makes wallet code simpler and may simplify migration to Hyper.
yeastplume pushed a commit that referenced this pull request Apr 16, 2018
This PR adresses #166
Error handling in wallet was ported to failure in #713
Using the same error model makes wallet code simpler and may simplify migration to Hyper.
@hashmap hashmap deleted the try-failure branch September 4, 2018 08:54
dpc pushed a commit to dpc/grin that referenced this pull request Oct 24, 2018
…#713)

* Initial version

* store failure parameters inside ErrorKind variants

* continue failure transformation

* 4 errors left

* still two errors

* return old code back

* finally compiling

* Fix compilation and test errors after merge
dpc pushed a commit to dpc/grin that referenced this pull request Oct 24, 2018
This PR adresses mimblewimble#166
Error handling in wallet was ported to failure in mimblewimble#713
Using the same error model makes wallet code simpler and may simplify migration to Hyper.
Makaric pushed a commit to Makaric/bitgrin that referenced this pull request May 16, 2026
…#713)

* Initial version

* store failure parameters inside ErrorKind variants

* continue failure transformation

* 4 errors left

* still two errors

* return old code back

* finally compiling

* Fix compilation and test errors after merge
Makaric pushed a commit to Makaric/bitgrin that referenced this pull request May 16, 2026
This PR adresses mimblewimble#166
Error handling in wallet was ported to failure in mimblewimble#713
Using the same error model makes wallet code simpler and may simplify migration to Hyper.
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

Successfully merging this pull request may close these issues.

6 participants