Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
.source()
support to client error enums and clean up some clien…
…t error definitions Summary: It'd be helpful to be able to call `.source()` on a Thrift client error, as that would make writing dynamic retry policies far easier and allow them to be used for multiple Thrift client methods. Normally to enable this, we just need to add the `#[source]` attribute (from thiserror) to the inner value of our error enums. But this results in bad error chaining and duplicated error messages when printing out the error chain (say with `anyhow`). I think the best solution here is to take a page out of [anyhow](https://docs.rs/anyhow/latest/anyhow/)'s book, specifically the `{:#}` semantics for `Display`. This way, we can omit printing the cause when printing with `{}` (and thus avoiding duplicate error messages when printing with `anyhow`), but one can choose to retain the behavior from before with `{:#}`. Aside from this, there's also a few cleanups we need to do with how Thrift client errors are laid out to support `.source()`, mainly: 1. Add `#[derive(thiserror::Error)]` to `ApplicationException` 2. This then requires us to remove the `impl From<ApplicationException> for Error` in `errors.rs` as it conflicts with `anyhow`'s existing blanket impl of `From<T: std::error::Error>` 3. Removing facebook#2 causes issues in `unionimpl.mustache` which does rely on that impl. However, `unionimpl`'s usage just returns a `ProtocolError` that wraps an `ApplicationException` that has a `ProtocolError` as an error code... so just flatten that to a new `ProtocolError` variant 4. It appears that this `unionimpl` was the only time we used the `ProtocolError::ApplicationException` variant, so just remove that. Feels weird to wrap an `ApplicationException` inside of a `ProtocolError` anyways. inspired by https://sabrinajewson.org/blog/errors#guidelines-for-good-errors. Reviewed By: edward-shen Differential Revision: D44808129 fbshipit-source-id: 051c4c499bc2aa309e6319e6da59ffb3788a55a3
- Loading branch information