about summary refs log tree commit diff
path: root/tvix/eval/src/nix_search_path.rs
diff options
context:
space:
mode:
authorAdam Joseph <adam@westernsemico.com>2023-09-10T05·02-0700
committerclbot <clbot@tvl.fyi>2023-09-24T21·54+0000
commit05f42519b53575ad3235b5e0a0cd7d71f04076a5 (patch)
tree82c5bdb55450615c0cf3169e25668426c9798e09 /tvix/eval/src/nix_search_path.rs
parent926459ce694536432c36d8f0d3fb25b821945852 (diff)
fix(tvix/eval): fix b/281 by adding Value::Catchable r/6650
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
Diffstat (limited to 'tvix/eval/src/nix_search_path.rs')
-rw-r--r--tvix/eval/src/nix_search_path.rs39
1 files changed, 22 insertions, 17 deletions
diff --git a/tvix/eval/src/nix_search_path.rs b/tvix/eval/src/nix_search_path.rs
index 3e553e62bb85..f86cffd6d615 100644
--- a/tvix/eval/src/nix_search_path.rs
+++ b/tvix/eval/src/nix_search_path.rs
@@ -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());
         }
     }
 }