about summary refs log tree commit diff
path: root/tvix/eval/src/nix_search_path.rs
diff options
context:
space:
mode:
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 3e553e62bb..f86cffd6d6 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());
         }
     }
 }