switch from abscissa::Context to color-eyre (#409)

Co-authored-by: Jane Lusby <jane@zfnd.org>
This commit is contained in:
Jane Lusby 2020-05-28 20:01:24 -07:00 committed by GitHub
parent e317b68b1d
commit da72c5a86a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 134 additions and 100 deletions

137
Cargo.lock generated
View File

@ -10,7 +10,7 @@ dependencies = [
"backtrace",
"canonical-path",
"chrono",
"color-backtrace",
"color-backtrace 0.3.0",
"generational-arena",
"gumdrop",
"libc",
@ -24,7 +24,7 @@ dependencies = [
"toml",
"tracing",
"tracing-log",
"tracing-subscriber",
"tracing-subscriber 0.1.6",
"wait-timeout",
]
@ -42,6 +42,15 @@ dependencies = [
"synstructure",
]
[[package]]
name = "addr2line"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a49806b9dadc843c61e7c97e72490ad7f7220ae249012fbda9ad0609457c0543"
dependencies = [
"gimli",
]
[[package]]
name = "aho-corasick"
version = "0.7.10"
@ -60,6 +69,15 @@ dependencies = [
"winapi 0.3.8",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi 0.3.8",
]
[[package]]
name = "arc-swap"
version = "0.3.11"
@ -109,26 +127,17 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "backtrace"
version = "0.3.46"
version = "0.3.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1e692897359247cc6bb902933361652380af0f1b7651ae5c5013407f30e109e"
checksum = "0df2f85c8a2abbe3b7d7e748052fdd9b76a0458fdeb16ad4223f5eca78c7c130"
dependencies = [
"backtrace-sys",
"addr2line",
"cfg-if",
"libc",
"object",
"rustc-demangle",
]
[[package]]
name = "backtrace-sys"
version = "0.1.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7de8aba10a69c8e8d7622c5710229485ec32e9d55fdad160ea559c086fdcd118"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "bech32"
version = "0.7.2"
@ -285,6 +294,44 @@ dependencies = [
"termcolor",
]
[[package]]
name = "color-backtrace"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5356ae4e07c994a2763226a8a991e5829ded78ac23f8ac88b3f3e69970db5163"
dependencies = [
"atty",
"backtrace",
"termcolor",
]
[[package]]
name = "color-eyre"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3cdd3caab1f4b52914ac0f232a97096f92c8ebac1632a6f8ca437adac85417f"
dependencies = [
"ansi_term 0.12.1",
"backtrace",
"color-backtrace 0.4.2",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "424ab1ba38a16ad93b9f895a76a4b238e79dad41a1ef3b15955c7fc785bea93f"
dependencies = [
"ansi_term 0.12.1",
"tracing-core",
"tracing-error",
]
[[package]]
name = "constant_time_eq"
version = "0.1.5"
@ -403,6 +450,15 @@ dependencies = [
"thiserror",
]
[[package]]
name = "eyre"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0fd0cbbcb0f8f25b9d9aada7235e1122c1d1a443293ee9efce58a579f9f5c25"
dependencies = [
"indenter",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
@ -561,6 +617,12 @@ dependencies = [
"wasi",
]
[[package]]
name = "gimli"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c"
[[package]]
name = "gumdrop"
version = "0.7.0"
@ -693,6 +755,12 @@ dependencies = [
"typenum",
]
[[package]]
name = "indenter"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0bd112d44d9d870a6819eb505d04dd92b5e4d94bb8c304924a0872ae7016fb5"
[[package]]
name = "indexmap"
version = "1.3.2"
@ -988,6 +1056,12 @@ dependencies = [
"libc",
]
[[package]]
name = "object"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cbca9424c482ee628fa549d9c812e2cd22f1180b9222c9200fdfa6eb31aecb2"
[[package]]
name = "once_cell"
version = "1.4.0"
@ -1530,6 +1604,15 @@ dependencies = [
"opaque-debug",
]
[[package]]
name = "sharded-slab"
version = "0.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06d5a3f5166fb5b42a5439f2eee8b9de149e235961e3eb21c5808fc3ea17ff3e"
dependencies = [
"lazy_static",
]
[[package]]
name = "signal-hook"
version = "0.1.13"
@ -1895,6 +1978,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 0.2.5",
]
[[package]]
name = "tracing-futures"
version = "0.2.4"
@ -1922,7 +2015,7 @@ version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "192ca16595cdd0661ce319e8eede9c975f227cdaabc4faaefdc256f43d852e45"
dependencies = [
"ansi_term",
"ansi_term 0.11.0",
"chrono",
"lazy_static",
"matchers",
@ -1933,6 +2026,16 @@ dependencies = [
"tracing-log",
]
[[package]]
name = "tracing-subscriber"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d53c40489aa69c9aed21ff483f26886ca8403df33bdc2d2f87c60c1617826d2"
dependencies = [
"sharded-slab",
"tracing-core",
]
[[package]]
name = "try-lock"
version = "0.2.2"
@ -2135,6 +2238,8 @@ version = "0.1.0"
dependencies = [
"abscissa_core",
"chrono",
"color-eyre",
"eyre",
"futures",
"gumdrop",
"hyper",

View File

@ -30,6 +30,8 @@ metrics = "0.12"
zebra-chain = { path = "../zebra-chain" }
zebra-network = { path = "../zebra-network" }
eyre = "0.4.2"
color-eyre = "0.3.2"
[dev-dependencies]
abscissa_core = { version = "0.5", features = ["testing"] }

View File

@ -1,12 +1,11 @@
//! `connect` subcommand - test stub for talking to zcashd
use crate::{
error::{Error, ErrorKind},
prelude::*,
};
use crate::prelude::*;
use abscissa_core::{Command, Options, Runnable};
use color_eyre::Report;
use eyre::eyre;
use futures::prelude::*;
/// `connect` subcommand
@ -42,7 +41,7 @@ impl Runnable for ConnectCmd {
}
impl ConnectCmd {
async fn connect(&self) -> Result<(), Error> {
async fn connect(&self) -> Result<(), Report> {
use zebra_network::{Request, Response};
info!("begin tower-based peer handling test stub");
@ -51,7 +50,7 @@ impl ConnectCmd {
let node = Buffer::new(
service_fn(|req| async move {
info!(?req);
Ok::<Response, Error>(Response::Nil)
Ok::<Response, Report>(Response::Nil)
}),
1,
);
@ -67,10 +66,7 @@ impl ConnectCmd {
tower::retry::Retry::new(zebra_network::RetryErrors, peer_set.clone());
info!("waiting for peer_set ready");
peer_set
.ready_and()
.await
.map_err(|e| Error::from(ErrorKind::Io.context(e)))?;
peer_set.ready_and().await.map_err(|e| eyre!(e))?;
info!("peer_set became ready");

View File

@ -13,10 +13,9 @@ use tower::{buffer::Buffer, Service, ServiceExt};
use zebra_network::{AddressBook, BoxedStdError, Request, Response};
use crate::{
error::{Error, ErrorKind},
prelude::*,
};
use crate::prelude::*;
use color_eyre::Report;
use eyre::eyre;
/// Whether our `SeedService` is poll_ready or not.
#[derive(Debug)]
@ -128,7 +127,7 @@ impl Runnable for SeedCmd {
}
impl SeedCmd {
async fn seed(&self) -> Result<(), Error> {
async fn seed(&self) -> Result<(), Report> {
info!("begin tower-based peer handling test stub");
let (addressbook_tx, addressbook_rx) = oneshot::channel();
@ -144,10 +143,7 @@ impl SeedCmd {
let _ = addressbook_tx.send(address_book);
info!("waiting for peer_set ready");
peer_set
.ready_and()
.await
.map_err(|e| Error::from(ErrorKind::Io.context(e)))?;
peer_set.ready_and().await.map_err(|e| eyre!(e))?;
info!("peer_set became ready");

View File

@ -1,64 +0,0 @@
//! Error types
use abscissa_core::error::{BoxError, Context};
use std::{
fmt::{self, Display},
io,
ops::Deref,
};
use thiserror::Error;
/// Kinds of errors
#[derive(Copy, Clone, Debug, Eq, Error, PartialEq)]
pub enum ErrorKind {
/// Error in configuration file
#[error("config error")]
Config,
/// Input/output error
#[error("I/O error")]
Io,
}
impl ErrorKind {
/// Create an error context from this error
pub fn context(self, source: impl Into<BoxError>) -> Context<ErrorKind> {
Context::new(self, Some(source.into()))
}
}
/// Error type
#[derive(Debug)]
pub struct Error(Box<Context<ErrorKind>>);
impl Deref for Error {
type Target = Context<ErrorKind>;
fn deref(&self) -> &Context<ErrorKind> {
&self.0
}
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
impl From<Context<ErrorKind>> for Error {
fn from(context: Context<ErrorKind>) -> Self {
Error(Box::new(context))
}
}
impl From<io::Error> for Error {
fn from(other: io::Error) -> Self {
ErrorKind::Io.context(other).into()
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.0.source()
}
}

View File

@ -30,5 +30,4 @@ mod components;
pub mod application;
pub mod commands;
pub mod config;
pub mod error;
pub mod prelude;