Rust in 2020, one more thing

We need to work on error handling.

It's a difficult thing to work on because a lot of people have strong opinions, but I think we should. Rust's error handling story at the moment is embarrassing, when people ask me what error library they should use, I cringe.

On the language-side, I think we are doing OK, but we could be doing much better. I don't have a preferred solution, but some problems:

  • writing Ok(()) sucks, I wish it wasn't needed,
  • Err(...)? is gross, but often better than the alternative of using return Err(...) because the former does some implicit conversion,
  • writing .map_err(Into::into) because you want to return the Ok variant as well as the Err variant is annoying.

I think we can also do better with some syntax sugar (or something) to make intention clearer, i.e., not writing Result everywhere.

2020 is the right time to do this work, because any new syntax is likely to be a little bit breaking, and so be a good candidate for the 2020 edition.

On the library-side, we should standardise on a single library and move it into std. Error handling is such a fundamental part of programming, and interoperability is so important, that it deserves to be part of the standard library.

There are so many libraries now:

  • error-chain
  • failure
  • fehler
  • err-derive
  • anyhow
  • thiserror
  • snafu
  • quick-error

and probably more.

There are good things we can learn from these, but I doubt we want to 'pick a winner'. More likely we need to take the best bits from each into std (this is already happening to some extent, std::error::Error has been improving, but we need to dramatically accelerate this effort).