use color_eyre for its backtrace feature and error reporting (#1855)

* use color_eyre for its backtrace feature and error reporting

* lost Cargo.lock update

* wrapper

* add error glue to be able to utilize eyre

* Update src/main.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update src/main.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* avoid duplicate error print

* Update src/main.rs

Co-authored-by: Andronik Ordian <write@reusable.software>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Andronik Ordian <write@reusable.software>
This commit is contained in:
Bernhard Schuster
2020-10-27 22:31:57 +01:00
committed by GitHub
parent 65106d7792
commit 5fbb8a381c
3 changed files with 103 additions and 2 deletions
+38 -2
View File
@@ -18,6 +18,42 @@
#![warn(missing_docs)]
fn main() -> cli::Result<()> {
cli::run()
use color_eyre::eyre;
use cli::Error as PolkaError;
use std::{error, fmt};
/// A helper to satisfy the requirements of `eyre`
/// compatible errors, which require `Send + Sync`
/// which are not satisfied by the `sp_*` crates.
#[derive(Debug)]
struct ErrorWrapper(std::sync::Arc<PolkaError>);
// nothing is going to be sent to another thread
// it merely exists to glue two distinct error
// types together where the requirements differ
// with `Sync + Send` and without them for `wasm`.
unsafe impl Sync for ErrorWrapper {}
unsafe impl Send for ErrorWrapper {}
impl error::Error for ErrorWrapper {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
(&*self.0).source().and_then(|e| e.source())
}
fn description(&self) -> &str {
"Error Wrapper"
}
}
impl fmt::Display for ErrorWrapper {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", &*self.0)
}
}
fn main() -> eyre::Result<()> {
color_eyre::install()?;
cli::run().map_err(|e| ErrorWrapper(std::sync::Arc::new(e)))?;
Ok(())
}