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
|
|
@ -124,22 +124,24 @@ pub struct NixSearchPath {
|
|||
impl NixSearchPath {
|
||||
/// Attempt to resolve the given `path` within this [`NixSearchPath`] using the
|
||||
/// path resolution rules for `<...>`-style paths
|
||||
pub fn resolve<P>(&self, io: &mut dyn EvalIO, path: P) -> Result<PathBuf, ErrorKind>
|
||||
pub fn resolve<P>(
|
||||
&self,
|
||||
io: &mut dyn EvalIO,
|
||||
path: P,
|
||||
) -> Result<Result<PathBuf, CatchableErrorKind>, ErrorKind>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
let path = path.as_ref();
|
||||
for entry in &self.entries {
|
||||
if let Some(p) = entry.resolve(io, path)? {
|
||||
return Ok(p);
|
||||
return Ok(Ok(p));
|
||||
}
|
||||
}
|
||||
Err(ErrorKind::CatchableErrorKind(
|
||||
CatchableErrorKind::NixPathResolution(format!(
|
||||
"path '{}' was not found in the Nix search path",
|
||||
path.display()
|
||||
)),
|
||||
))
|
||||
Ok(Err(CatchableErrorKind::NixPathResolution(format!(
|
||||
"path '{}' was not found in the Nix search path",
|
||||
path.display()
|
||||
))))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -204,19 +206,19 @@ mod tests {
|
|||
let nix_search_path = NixSearchPath::from_str("./.").unwrap();
|
||||
let mut io = StdIO {};
|
||||
let res = nix_search_path.resolve(&mut io, "src").unwrap();
|
||||
assert_eq!(res, current_dir().unwrap().join("src").clean());
|
||||
assert_eq!(
|
||||
res.unwrap().to_path_buf(),
|
||||
current_dir().unwrap().join("src").clean()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_resolution() {
|
||||
let nix_search_path = NixSearchPath::from_str("./.").unwrap();
|
||||
let mut io = StdIO {};
|
||||
let err = nix_search_path.resolve(&mut io, "nope").unwrap_err();
|
||||
let err = nix_search_path.resolve(&mut io, "nope").unwrap();
|
||||
assert!(
|
||||
matches!(
|
||||
err,
|
||||
ErrorKind::CatchableErrorKind(CatchableErrorKind::NixPathResolution(..))
|
||||
),
|
||||
matches!(err, Err(CatchableErrorKind::NixPathResolution(..))),
|
||||
"err = {err:?}"
|
||||
);
|
||||
}
|
||||
|
|
@ -226,7 +228,7 @@ mod tests {
|
|||
let nix_search_path = NixSearchPath::from_str("./.:/").unwrap();
|
||||
let mut io = StdIO {};
|
||||
let res = nix_search_path.resolve(&mut io, "etc").unwrap();
|
||||
assert_eq!(res, Path::new("/etc"));
|
||||
assert_eq!(res.unwrap().to_path_buf(), Path::new("/etc"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -234,7 +236,10 @@ mod tests {
|
|||
let nix_search_path = NixSearchPath::from_str("/:tvix=.").unwrap();
|
||||
let mut io = StdIO {};
|
||||
let res = nix_search_path.resolve(&mut io, "tvix/src").unwrap();
|
||||
assert_eq!(res, current_dir().unwrap().join("src").clean());
|
||||
assert_eq!(
|
||||
res.unwrap().to_path_buf(),
|
||||
current_dir().unwrap().join("src").clean()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -242,7 +247,7 @@ mod tests {
|
|||
let nix_search_path = NixSearchPath::from_str("/:tvix=.").unwrap();
|
||||
let mut io = StdIO {};
|
||||
let res = nix_search_path.resolve(&mut io, "tvix").unwrap();
|
||||
assert_eq!(res, current_dir().unwrap().clean());
|
||||
assert_eq!(res.unwrap().to_path_buf(), current_dir().unwrap().clean());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue