Skip to content
Snippets Groups Projects
Commit 5fbb8a38 authored by Bernhard Schuster's avatar Bernhard Schuster Committed by GitHub
Browse files

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: default avatarBastian Köcher <bkchr@users.noreply.github.com>

* Update src/main.rs

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

* avoid duplicate error print

* Update src/main.rs

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

Co-authored-by: default avatarBastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: default avatarAndronik Ordian <write@reusable.software>
parent 65106d77
Branches
No related merge requests found
......@@ -752,6 +752,32 @@ dependencies = [
"bitflags",
]
[[package]]
name = "color-eyre"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2a5123db5af8349c41c43ed0e5dca1cd56c911ea0c4ce6e6ff30f159fa5d27e"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell 1.4.1",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a99aa4aa18448eef4c7d3f86d2720d2d8cad5c860fe9ff9b279293efdc8f5be"
dependencies = [
"ansi_term 0.11.0",
"tracing-core",
"tracing-error",
]
[[package]]
name = "concurrent-queue"
version = "1.2.2"
......@@ -1297,6 +1323,16 @@ dependencies = [
"futures 0.3.5",
]
[[package]]
name = "eyre"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c5cb4dc433c59f09df4b4450f649cbfed61e8a3505abe32e4154066439157e"
dependencies = [
"indenter",
"once_cell 1.4.1",
]
[[package]]
name = "failure"
version = "0.1.8"
......@@ -2315,6 +2351,12 @@ dependencies = [
"syn 1.0.33",
]
[[package]]
name = "indenter"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0bd112d44d9d870a6819eb505d04dd92b5e4d94bb8c304924a0872ae7016fb5"
[[package]]
name = "indexmap"
version = "1.4.0"
......@@ -3767,6 +3809,12 @@ dependencies = [
"stable_deref_trait",
]
[[package]]
name = "owo-colors"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a1250cdd103eef6bd542b5ae82989f931fc00a41a27f60377338241594410f3"
[[package]]
name = "pallet-authority-discovery"
version = "2.0.0"
......@@ -4700,6 +4748,7 @@ name = "polkadot"
version = "0.8.26"
dependencies = [
"assert_cmd",
"color-eyre",
"futures 0.3.5",
"nix 0.17.0",
"parity-util-mem",
......@@ -9251,6 +9300,16 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "tracing-error"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4d7c0b83d4a500748fa5879461652b361edf5c9d51ede2a2ac03875ca185e24"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-futures"
version = "0.2.4"
......
......@@ -13,6 +13,7 @@ readme = "README.md"
[dependencies]
cli = { package = "polkadot-cli", path = "cli" }
color-eyre = "0.5.6"
futures = "0.3.4"
service = { package = "polkadot-service", path = "node/service" }
parity-util-mem = { version = "*", default-features = false, features = ["jemalloc-global"] }
......@@ -72,6 +73,11 @@ members = [
[badges]
maintenance = { status = "actively-developed" }
# make sure dev builds with backtrace do
# not slow us down
[profile.dev.package.backtrace]
opt-level = 3
[profile.release]
# Polkadot runtime requires unwinding.
panic = "unwind"
......
......@@ -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(())
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment