git.delta.rocks / jrsonnet / refs/commits / 3b19e49816fb

difftreelog

feat(evaluator) anyhow integration

Yaroslav Bolyukin2021-01-28parent: #f91abe0.patch.diff
in: master

3 files changed

modifiedCargo.lockdiffbeforeafterboth
before · Cargo.lock
61 packageslockfile v1
after · Cargo.lock
62 packageslockfile v1
modifiedcrates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth
--- 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"
modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
--- 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<anyhow::Error>)
+}
+
+#[cfg(feature = "anyhow-error")]
+impl From<anyhow::Error> for LocError {
+	fn from(e: anyhow::Error) -> Self {
+		Self::new(Error::Other(Rc::new(e)))
+	}
 }
+
 impl From<Error> for LocError {
 	fn from(e: Error) -> Self {
 		Self::new(e)