diff options
Diffstat (limited to 'tvix/eval/src/value')
-rw-r--r-- | tvix/eval/src/value/attrs.rs | 2 | ||||
-rw-r--r-- | tvix/eval/src/value/json.rs | 6 | ||||
-rw-r--r-- | tvix/eval/src/value/mod.rs | 15 |
3 files changed, 14 insertions, 9 deletions
diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs index 23a2acb0b9a4..c9f04b54cc57 100644 --- a/tvix/eval/src/value/attrs.rs +++ b/tvix/eval/src/value/attrs.rs @@ -375,7 +375,7 @@ impl NixAttrs { continue; } - Value::Catchable(err) => return Ok(Err(err)), + Value::Catchable(err) => return Ok(Err(*err)), other => return Err(ErrorKind::InvalidAttributeName(other)), } diff --git a/tvix/eval/src/value/json.rs b/tvix/eval/src/value/json.rs index efd2763f1c36..7ab1655d9055 100644 --- a/tvix/eval/src/value/json.rs +++ b/tvix/eval/src/value/json.rs @@ -61,7 +61,7 @@ impl Value { ) .await? { - Value::Catchable(cek) => return Ok(Err(cek)), + Value::Catchable(cek) => return Ok(Err(*cek)), Value::String(s) => return Ok(Ok(Json::String(s.to_str()?.to_owned()))), _ => panic!("Value::coerce_to_string_() returned a non-string!"), } @@ -88,7 +88,7 @@ impl Value { Json::Object(out) } - Value::Catchable(c) => return Ok(Err(c)), + Value::Catchable(c) => return Ok(Err(*c)), val @ Value::Closure(_) | val @ Value::Thunk(_) @@ -110,7 +110,7 @@ impl Value { /// Value::Json. pub(crate) async fn into_json_generator(self, co: GenCo) -> Result<Value, ErrorKind> { match self.into_json(&co).await? { - Err(cek) => Ok(Value::Catchable(cek)), + Err(cek) => Ok(Value::from(cek)), Ok(json) => Ok(Value::Json(Box::new(json))), } } diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index 3407dd52029f..efe2d09e33cd 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -84,12 +84,13 @@ pub enum Value { FinaliseRequest(bool), #[serde(skip)] - Catchable(CatchableErrorKind), + Catchable(Box<CatchableErrorKind>), } impl From<CatchableErrorKind> for Value { + #[inline] fn from(c: CatchableErrorKind) -> Value { - Value::Catchable(c) + Value::Catchable(Box::new(c)) } } @@ -97,8 +98,12 @@ impl<V> From<Result<V, CatchableErrorKind>> for Value where Value: From<V>, { + #[inline] fn from(v: Result<V, CatchableErrorKind>) -> Value { - v.map_or_else(Value::Catchable, |v| v.into()) + match v { + Ok(v) => v.into(), + Err(e) => Value::Catchable(Box::new(e)), + } } } @@ -776,8 +781,8 @@ impl Value { b = b.force(&co, span.clone()).await?; } let result = match (a, b) { - (Value::Catchable(c), _) => return Ok(Err(c)), - (_, Value::Catchable(c)) => return Ok(Err(c)), + (Value::Catchable(c), _) => return Ok(Err(*c)), + (_, Value::Catchable(c)) => return Ok(Err(*c)), // same types (Value::Integer(i1), Value::Integer(i2)) => i1.cmp(&i2), (Value::Float(f1), Value::Float(f2)) => f1.total_cmp(&f2), |