fix(tvix/eval): fix b/281 by adding Value::Catchable
This commit makes catchable errors a variant of Value. The main downside of this approach is that we lose the ability to use Rust's `?` syntax for propagating catchable errors. Change-Id: Ibe89438d8a70dcec29e016df692b5bf88a5cad13 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9289 Reviewed-by: tazjin <tazjin@tvl.su> Autosubmit: Adam Joseph <adam@westernsemico.com> Tested-by: BuildkiteCI
This commit is contained in:
parent
926459ce69
commit
05f42519b5
16 changed files with 320 additions and 247 deletions
|
|
@ -25,7 +25,10 @@ async fn import_impl(
|
|||
mut args: Vec<Value>,
|
||||
) -> Result<Value, ErrorKind> {
|
||||
// TODO(sterni): canon_path()?
|
||||
let mut path = coerce_value_to_path(&co, args.pop().unwrap()).await?;
|
||||
let mut path = match coerce_value_to_path(&co, args.pop().unwrap()).await? {
|
||||
Err(cek) => return Ok(Value::Catchable(cek)),
|
||||
Ok(path) => path,
|
||||
};
|
||||
|
||||
if path.is_dir() {
|
||||
path.push("default.nix");
|
||||
|
|
@ -36,11 +39,8 @@ async fn import_impl(
|
|||
}
|
||||
|
||||
// TODO(tazjin): make this return a string directly instead
|
||||
let contents = generators::request_read_to_string(&co, path.clone())
|
||||
.await
|
||||
.to_str()?
|
||||
.as_str()
|
||||
.to_string();
|
||||
let contents: Value = generators::request_read_to_string(&co, path.clone()).await;
|
||||
let contents = contents.to_str()?.as_str().to_string();
|
||||
|
||||
let parsed = rnix::ast::Root::parse(&contents);
|
||||
let errors = parsed.errors();
|
||||
|
|
|
|||
|
|
@ -396,11 +396,11 @@ impl Compiler<'_> {
|
|||
} else if raw_path.starts_with('<') {
|
||||
// TODO: decide what to do with findFile
|
||||
if raw_path.len() == 2 {
|
||||
return self.emit_error(
|
||||
node,
|
||||
ErrorKind::CatchableErrorKind(CatchableErrorKind::NixPathResolution(
|
||||
return self.emit_constant(
|
||||
Value::Catchable(CatchableErrorKind::NixPathResolution(
|
||||
"Empty <> path not allowed".into(),
|
||||
)),
|
||||
node,
|
||||
);
|
||||
}
|
||||
let path = &raw_path[1..(raw_path.len() - 1)];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue