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
--- 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",
modifiedcrates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth
before · crates/jrsonnet-evaluator/Cargo.toml
1[package]2name = "jrsonnet-evaluator"3description = "jsonnet interpreter"4version = "0.3.4"5authors = ["Yaroslav Bolyukin <iam@lach.pw>"]6license = "MIT"7edition = "2018"89[features]10default = ["serialized-stdlib", "faster", "explaining-traces", "serde-json"]11# Serializes standard library AST instead of parsing them every run12serialized-stdlib = ["serde", "bincode", "jrsonnet-parser/deserialize"]13# Allow to convert Val into serde_json::Value and backwards14serde-json = ["serde", "serde_json"]15# Replace some standard library functions with faster implementations (I.e manifestJsonEx)16# Library works fine without this feature, but requires more memory and time for std function calls17faster = []18# Rustc-like trace visualization19explaining-traces = ["annotate-snippets"]2021# Unlocks extra features, but works only on unstable22unstable = []2324[dependencies]25jrsonnet-interner = { path = "../jrsonnet-interner" }26jrsonnet-parser = { path = "../jrsonnet-parser", version = "0.3.4" }27jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.3.4" }28jrsonnet-types = { path = "../jrsonnet-types", version = "0.3.4" }29pathdiff = "0.2.0"3031closure = "0.3.0"32indexmap = "1.6"3334md5 = "0.7.0"35base64 = "0.13.0"36rustc-hash = "1.1.0"3738thiserror = "1.0"3940# Serialized stdlib41[dependencies.serde]42version = "1.0"43optional = true44[dependencies.bincode]45version = "1.3.1"46optional = true4748# Serde json49[dependencies.serde_json]50version = "1.0"51optional = true5253# Explaining traces54[dependencies.annotate-snippets]55version = "0.9.0"56features = ["color"]57optional = true5859[build-dependencies]60jrsonnet-parser = { path = "../jrsonnet-parser", features = ["serialize", "deserialize"], version = "0.3.4" }61jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.3.4" }62serde = "1.0"63bincode = "1.3.1"
after · crates/jrsonnet-evaluator/Cargo.toml
1[package]2name = "jrsonnet-evaluator"3description = "jsonnet interpreter"4version = "0.3.4"5authors = ["Yaroslav Bolyukin <iam@lach.pw>"]6license = "MIT"7edition = "2018"89[features]10default = ["serialized-stdlib", "faster", "explaining-traces", "serde-json"]11# Serializes standard library AST instead of parsing them every run12serialized-stdlib = ["serde", "bincode", "jrsonnet-parser/deserialize"]13# Allow to convert Val into serde_json::Value and backwards14serde-json = ["serde", "serde_json"]15# Replace some standard library functions with faster implementations (I.e manifestJsonEx)16# Library works fine without this feature, but requires more memory and time for std function calls17faster = []18# Rustc-like trace visualization19explaining-traces = ["annotate-snippets"]20# Allows library authors to throw custom errors21anyhow-error = ["anyhow"]2223# Unlocks extra features, but works only on unstable24unstable = []2526[dependencies]27jrsonnet-interner = { path = "../jrsonnet-interner" }28jrsonnet-parser = { path = "../jrsonnet-parser", version = "0.3.4" }29jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.3.4" }30jrsonnet-types = { path = "../jrsonnet-types", version = "0.3.4" }31pathdiff = "0.2.0"3233closure = "0.3.0"34indexmap = "1.6"3536md5 = "0.7.0"37base64 = "0.13.0"38rustc-hash = "1.1.0"3940thiserror = "1.0"4142[dependencies.anyhow]43version = "1.0"44optional = true4546# Serialized stdlib47[dependencies.serde]48version = "1.0"49optional = true50[dependencies.bincode]51version = "1.3.1"52optional = true5354# Serde json55[dependencies.serde_json]56version = "1.0"57optional = true5859# Explaining traces60[dependencies.annotate-snippets]61version = "0.9.0"62features = ["color"]63optional = true6465[build-dependencies]66jrsonnet-parser = { path = "../jrsonnet-parser", features = ["serialize", "deserialize"], version = "0.3.4" }67jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "0.3.4" }68serde = "1.0"69bincode = "1.3.1"
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)