Error handling with failure (using Error and ErrorKind)#713
Conversation
|
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? |
|
@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 |
|
Forgot to mention that we had to implement s |
|
|
||
| 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.
This comment was marked as spam.
Sorry, something went wrong.
| fn from(e: hyper::Error) -> Error { | ||
| Error::Hyper(e) | ||
| } | ||
| impl From<ErrorKind> for Error { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| "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.
This comment was marked as spam.
Sorry, something went wrong.
|
Thanks for nice and helpful feedback. Merged with the current master. We will check couple of places where |
|
It's ready for review. |
|
@hashmap looks like there are some conflicts to clean up. |
|
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 |
|
Sounds like everyone is on board? I'm going to go ahead and merge. |
|
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: 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? |
|
@heunglee I'd suggest to map ErrorKind's variants (https://github.com/mimblewimble/grin/blob/master/wallet/src/types.rs#L76) to HTTP status codes |
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.
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.
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.
…#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
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.
…#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
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.
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.