First of all: thank you for all the help. I really appreciate it.
But I am sorry to say that all my attempts are doing nothing more than adding frustration and enforcing my idea that errors in rust are completely screwed.
I updated handlebars to 0.30-beta.4.
This is using my own Error as described in “An Error and an ErroKind pair” in the failure site:
self.engine.read().unwrap()
.render(tpl_type, data
.context(ErrorKind::Error(format!("Unable to render template {}", tpl_type)))?
Error:
error[E0308]: match arms have incompatible types
--> src/tpl/engine_handlebars.rs:100:3
...
^ expected enum `std::result::Result`, found struct `std::string::String`
|
= note: expected type `std::result::Result<std::string::String, errors::Error>`
found type `std::string::String`
Removing the question mark:
error[E0308]: mismatched types
--> src/tpl/engine_handlebars.rs:100:3
|
99 | pub fn render_page(&self, tpl_type: &str, data: &Object) -> Result<String, Error> {
| --------------------- expected `std::result::Result<std::string::String, errors::Error>` because of return type
...
^ expected struct `errors::Error`, found struct `failure::Context`
|
= note: expected type `std::result::Result<_, errors::Error>`
found type `std::result::Result<_, failure::Context<errors::ErrorKind>>`
Using failure’s Error:
error[E0308]: match arms have incompatible types
--> src/tpl/engine_handlebars.rs:100:3
|
100 | / self.engine.read().unwrap()
101 | | .render(tpl_type, data)
102 | | .context(format!("Unable to render template {}", tpl_type))?
| |_______________________________________________________________^ expected enum `std::result::Result`, found struct `std::string::String`
|
= note: expected type `std::result::Result<std::string::String, failure::Error>`
found type `std::string::String`
Removing the question mark:
error[E0308]: mismatched types
--> src/tpl/engine_handlebars.rs:100:3
|
99 | pub fn render_page(&self, tpl_type: &str, data: &Object) -> Result<String, Error> {
| --------------------- expected `std::result::Result<std::string::String, failure::Error>` because of return type
100 | / self.engine.read().unwrap()
101 | | .render(tpl_type, data)
102 | | .context(format!("Unable to render template {}", tpl_type))
| |______________________________________________________________^ expected struct `failure::Error`, found struct `failure::Context`
|
= note: expected type `std::result::Result<_, failure::Error>`
found type `std::result::Result<_, failure::Context<std::string::String>>`
I can probably work out a solution by spending more time on it, wrapping errors more, implementing more traits, etc.
The point is: I should not have to.