From 3b19e49816fbbbecb5ed1a02f6976d318062306b Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Thu, 28 Jan 2021 03:29:31 +0000 Subject: [PATCH] feat(evaluator): anyhow integration --- --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,12 @@ ] [[package]] +name = "anyhow" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" + +[[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -163,6 +169,7 @@ version = "0.3.4" dependencies = [ "annotate-snippets", + "anyhow", "base64", "bincode", "closure", --- a/crates/jrsonnet-evaluator/Cargo.toml +++ b/crates/jrsonnet-evaluator/Cargo.toml @@ -17,6 +17,8 @@ faster = [] # Rustc-like trace visualization explaining-traces = ["annotate-snippets"] +# Allows library authors to throw custom errors +anyhow-error = ["anyhow"] # Unlocks extra features, but works only on unstable unstable = [] @@ -37,6 +39,10 @@ thiserror = "1.0" +[dependencies.anyhow] +version = "1.0" +optional = true + # Serialized stdlib [dependencies.serde] version = "1.0" --- a/crates/jrsonnet-evaluator/src/error.rs +++ b/crates/jrsonnet-evaluator/src/error.rs @@ -123,7 +123,19 @@ TypeError(TypeLocError), #[error("sort error: {0}")] Sort(#[from] SortError), + + #[cfg(feature = "anyhow-error")] + #[error(transparent)] + Other(Rc) +} + +#[cfg(feature = "anyhow-error")] +impl From for LocError { + fn from(e: anyhow::Error) -> Self { + Self::new(Error::Other(Rc::new(e))) + } } + impl From for LocError { fn from(e: Error) -> Self { Self::new(e) -- gitstuff