Migrate application from error-chain to failure


#1

Hello,

I have a little application with error management done with error-chain.
I would like to migrate it to failure.

I have read thought failure documentation, but I can’t figure out which pattern should I use for myself.

Initially I tried to use Result<T, failure::Error> as return type.
However, I got errors like

the trait `std::convert::From<failure::Error>` is not implemented for `jsonrpc_core::Error`

As I understand it happens because jsonrpc_core::Error doesn’t implement std::error::Error.
And I can’t implement it because both types are remote.

As far as understand it means that I have to return not failure::Error but my custom error type.
So, then I tried to use Result<T, Error> where Error is my enum.

I created a Gist file with what I got with error-chain and how I changed it with failure.
Though I totally not sure if I made all the things right. In particular, now I have to write down few impl From<> for Error.
I guess if it should be done or maybe there is a better way.

Could you please to review the code and provide any comments?
Please tell me if I could provide any additional information.

Thanks.


#2

I too would like to understand how to migrate from error-chain to failure – as well as a rationale for doing so. For example, failure 1 doesn’t seem to have bail! which the older version had. Also the failure docs show Result<…, Error> whereas for error-chain it is just Result<…>.

I guess what I’d like to see is an error-chain example that used some foreign links, a custom error, and some string (i.e., bail!) errors, and the same example in failure.


#3

I was stumbling upon that but once I posted this question I realized a way this could be done.
If you are interested you can see a commit where I did it.


#4

see https://boats.gitlab.io/blog/post/2018-02-22-failure-1.0/#the-bail-macro


#5

That post refers to failure 1.0, yet the 1.0 docs don’t mention the bail! or throw! mentioned in the blog post. But both bail! and throw! appear in 0.1.1.

So, am I right in assuming that now I should use 0.1.1 with the bail! and throw! features on the assumption that these will work with 1.0 which I think is what the blog is saying? Or would it be better to wait for the 1.0 release?


#6

I’m not sure what the release schedule for 1.0 is nowadays, so I’d stick to 1.1.