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

difftreelog

feat enable friendly-errors by default

Yaroslav Bolyukin2023-06-14parent: #bbe146e.patch.diff
in: master

4 files changed

modifiedcrates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth
8edition = "2021"8edition = "2021"
99
10[features]10[features]
11default = ["explaining-traces", "friendly-errors"]11default = ["explaining-traces"]
12# Rustc-like trace visualization12# Rustc-like trace visualization
13explaining-traces = ["annotate-snippets"]13explaining-traces = ["annotate-snippets"]
14# Allows library authors to throw custom errors14# Allows library authors to throw custom errors
15anyhow-error = ["anyhow"]15anyhow-error = ["anyhow"]
16# Provides helpful explaintations to errors, at cost of adding
17# more dependencies and slowing down error path
18friendly-errors = ["strsim"]
19# Adds ability to build import closure in async16# Adds ability to build import closure in async
20async-import = ["async-trait"]17async-import = ["async-trait"]
2118
45rustc-hash = "1.1"42rustc-hash = "1.1"
4643
47thiserror = "1.0"44thiserror = "1.0"
45# Friendly errors
46strsim = { version = "0.10.0" }
4847
49serde = "1.0"48serde = "1.0"
5049
51anyhow = { version = "1.0", optional = true }50anyhow = { version = "1.0", optional = true }
52# Friendly errors
53strsim = { version = "0.10.0", optional = true }
54# Serialized stdlib51# Serialized stdlib
55bincode = { version = "1.3", optional = true }52bincode = { version = "1.3", optional = true }
56# Explaining traces53# Explaining traces
modifiedcrates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/ctx.rs
+++ b/crates/jrsonnet-evaluator/src/ctx.rs
@@ -51,17 +51,6 @@
 		self.0.sup.as_ref()
 	}
 
-	#[cfg(not(feature = "friendly-errors"))]
-	pub fn binding(&self, name: IStr) -> Result<Thunk<Val>> {
-		Ok(self
-			.0
-			.bindings
-			.get(&name)
-			.cloned()
-			.ok_or(VariableIsNotDefined(name, vec![]))?)
-	}
-
-	#[cfg(feature = "friendly-errors")]
 	pub fn binding(&self, name: IStr) -> Result<Thunk<Val>> {
 		use std::cmp::Ordering;
 
modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -1,6 +1,7 @@
 use std::{
+	cmp::Ordering,
 	fmt::{Debug, Display},
-	path::PathBuf, cmp::Ordering,
+	path::PathBuf,
 };
 
 use jrsonnet_gcmodule::Trace;
@@ -79,9 +80,8 @@
 		if conf < 0.8 {
 			continue;
 		}
-		if field.as_str() == key.as_str() {
-			panic!("looks like string pooling failure, please write any info regarding this crash to https://github.com/CertainLach/jrsonnet/issues/113, thanks!");
-		}
+		assert!(field.as_str() != key.as_str(), "looks like string pooling failure, please write any info regarding this crash to https://github.com/CertainLach/jrsonnet/issues/113, thanks!");
+
 		heap.push((conf, field));
 	}
 	heap.sort_by(|a, b| b.0.partial_cmp(&a.0).unwrap_or(Ordering::Equal));
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -1,4 +1,4 @@
-use std::{cmp::Ordering, rc::Rc};
+use std::rc::Rc;
 
 use jrsonnet_gcmodule::{Cc, Trace};
 use jrsonnet_interner::IStr;
@@ -12,7 +12,7 @@
 use crate::{
 	arr::ArrValue,
 	destructure::evaluate_dest,
-	error::{ErrorKind::*, suggest_object_fields},
+	error::{suggest_object_fields, ErrorKind::*},
 	evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op},
 	function::{CallLocation, FuncDesc, FuncVal},
 	throw,