git.delta.rocks / jrsonnet / refs/commits / 59f19ba582ad

difftreelog

refactor drop runtime_error! usage

pospolqmYaroslav Bolyukin2026-05-05parent: #cf33b6e.patch.diff
in: master

4 files changed

modifiedcrates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/arrays.rs
+++ b/crates/jrsonnet-stdlib/src/arrays.rs
@@ -3,7 +3,6 @@
 use jrsonnet_evaluator::{
 	Either, IStr, ObjValue, ObjValueBuilder, Result, ResultExt, Thunk, Val, bail, error,
 	function::{NativeFn, builtin},
-	runtime_error,
 	typed::{BoundedUsize, Either2, FromUntyped},
 	val::{ArrValue, IndexableVal, equals},
 };
@@ -40,8 +39,7 @@
 	Ok(match what {
 		Either2::A(s) => Val::string(s.repeat(count as usize)),
 		Either2::B(arr) => Val::Arr(
-			ArrValue::repeated(arr, count)
-				.ok_or_else(|| runtime_error!("repeated length overflow"))?,
+			ArrValue::repeated(arr, count).ok_or_else(|| error!("repeated length overflow"))?,
 		),
 	})
 }
modifiedcrates/jrsonnet-stdlib/src/encoding.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/encoding.rs
+++ b/crates/jrsonnet-stdlib/src/encoding.rs
@@ -1,8 +1,7 @@
 use base64::{Engine, engine::general_purpose::STANDARD};
 use jrsonnet_evaluator::{
-	IBytes, IStr, Result, bail,
+	IBytes, IStr, Result, bail, error,
 	function::builtin,
-	runtime_error,
 	typed::{Either, Either2},
 };
 
@@ -35,7 +34,7 @@
 pub fn builtin_base64_decode_bytes(str: IStr) -> Result<IBytes> {
 	Ok(STANDARD
 		.decode(str.as_bytes())
-		.map_err(|e| runtime_error!("invalid base64: {e}"))?
+		.map_err(|e| error!("invalid base64: {e}"))?
 		.as_slice()
 		.into())
 }
@@ -44,10 +43,10 @@
 pub fn builtin_base64_decode(str: IStr, #[default(false)] lossy: bool) -> Result<String> {
 	let bytes = STANDARD
 		.decode(str.as_bytes())
-		.map_err(|e| runtime_error!("invalid base64: {e}"))?;
+		.map_err(|e| error!("invalid base64: {e}"))?;
 	if lossy {
 		Ok(String::from_utf8_lossy(&bytes).to_string())
 	} else {
-		String::from_utf8(bytes).map_err(|e| runtime_error!("bad utf8: {e}"))
+		String::from_utf8(bytes).map_err(|e| error!("bad utf8: {e}"))
 	}
 }
modifiedcrates/jrsonnet-stdlib/src/parse.rsdiffbeforeafterboth
before · crates/jrsonnet-stdlib/src/parse.rs
1use jrsonnet_evaluator::{IStr, Result, Val, function::builtin, runtime_error};2use serde_saphyr::options;34#[builtin]5pub fn builtin_parse_json(str: IStr) -> Result<Val> {6	let value: Val =7		serde_json::from_str(&str).map_err(|e| runtime_error!("failed to parse json: {e}"))?;8	Ok(value)9}1011#[builtin]12pub fn builtin_parse_yaml(str: IStr) -> Result<Val> {13	let needs_synthetic_null = str.trim_end().ends_with("\n---");1415	let mut out = serde_saphyr::from_multiple_with_options::<Val>(16		&str,17		options! {18			// Golang/C++ compat19			legacy_octal_numbers: true,20			// Disable budget limits - we trust the YAML input21			budget: None,22		},23	)24	.map_err(|e| runtime_error!("failed to parse yaml: {e}"))?;2526	// saphyr and other yaml implementations disagree on how to handle an empty document in multi-document stream.27	// Saphyr only considers document started after anything is emitted after the document delimiter28	if needs_synthetic_null {29		out.push(Val::Null);30	}3132	Ok(if out.is_empty() {33		Val::Null34	} else if out.len() == 1 {35		out.into_iter().next().unwrap()36	} else {37		Val::Arr(out.into())38	})39}
modifiedcrates/jrsonnet-stdlib/src/strings.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/strings.rs
+++ b/crates/jrsonnet-stdlib/src/strings.rs
@@ -206,17 +206,15 @@
 #[builtin]
 pub fn builtin_bigint(v: Either![f64, IStr]) -> Result<Val> {
 	use Either2::*;
-	use jrsonnet_evaluator::runtime_error;
+	use jrsonnet_evaluator::error;
 	Ok(match v {
-		A(a) => {
-			Val::BigInt(Box::new(a.to_string().parse().map_err(|e| {
-				runtime_error!("number is not convertible to bigint: {e}")
-			})?))
-		}
+		A(a) => Val::BigInt(Box::new(
+			a.to_string()
+				.parse()
+				.map_err(|e| error!("number is not convertible to bigint: {e}"))?,
+		)),
 		B(b) => Val::BigInt(Box::new(
-			b.as_str()
-				.parse()
-				.map_err(|e| runtime_error!("bad bigint: {e}"))?,
+			b.as_str().parse().map_err(|e| error!("bad bigint: {e}"))?,
 		)),
 	})
 }