refactor(eval): make CatchableErrorKind::Throw hold a NixString
The messages we can throw are not necessarily UTF-8 strings. The to_string() in there did store the result of the Display impl, which is a quoted string. Change-Id: I65a77ccc7f2d62ff06a2a9458cdb7e7292f132b0 Reviewed-on: https://cl.snix.dev/c/snix/+/30489 Tested-by: besadii Autosubmit: Florian Klink <flokli@flokli.de> Reviewed-by: Bence Nemes <nemes.bence1@gmail.com>
This commit is contained in:
parent
bbc1efdb0e
commit
7eb15f8123
3 changed files with 7 additions and 16 deletions
|
|
@ -1405,11 +1405,10 @@ mod pure_builtins {
|
|||
if message.is_catchable() {
|
||||
return Ok(message);
|
||||
}
|
||||
// TODO(sterni): coerces to string
|
||||
|
||||
// TODO(sterni): coerce to string
|
||||
// We do not care about the context here explicitly.
|
||||
Ok(Value::from(CatchableErrorKind::Throw(
|
||||
message.to_contextful_str()?.to_string().into(),
|
||||
)))
|
||||
Ok(Value::from(CatchableErrorKind::Throw(message.to_str()?)))
|
||||
}
|
||||
|
||||
#[builtin("toString")]
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ use crate::{SourceCode, Value};
|
|||
#[derive(thiserror::Error, Clone, Debug)]
|
||||
pub enum CatchableErrorKind {
|
||||
#[error("error thrown: {0}")]
|
||||
Throw(Box<str>),
|
||||
Throw(NixString),
|
||||
|
||||
#[error("assertion failed")]
|
||||
AssertionFailed,
|
||||
|
|
|
|||
|
|
@ -18,11 +18,7 @@ fn test_source_builtin() {
|
|||
);
|
||||
|
||||
let value = result.value.unwrap();
|
||||
assert!(
|
||||
matches!(value, Value::Integer(42)),
|
||||
"expected the integer 42, but got {}",
|
||||
value,
|
||||
);
|
||||
assert_matches!(value, Value::Integer(i) if i == 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -32,11 +28,7 @@ fn skip_broken_bytecode() {
|
|||
.evaluate(/* code = */ "x", None);
|
||||
|
||||
assert_eq!(result.errors.len(), 1);
|
||||
|
||||
assert!(matches!(
|
||||
result.errors[0].kind,
|
||||
ErrorKind::UnknownStaticVariable
|
||||
));
|
||||
assert_matches!(result.errors[0].kind, ErrorKind::UnknownStaticVariable);
|
||||
}
|
||||
|
||||
/// Checks that deep forcing happens in lexicographic key order
|
||||
|
|
@ -58,6 +50,6 @@ fn key_order_deep_force() {
|
|||
|
||||
assert_matches!(
|
||||
&result.errors[0].kind,
|
||||
ErrorKind::CatchableError(CatchableErrorKind::Throw(s)) if s.as_ref() == "\"aaa\""
|
||||
ErrorKind::CatchableError(CatchableErrorKind::Throw(s)) if s == &NixString::from("aaa")
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue