diff options
author | Conrad Ludgate <conradludgate@gmail.com> | 2021-11-13 19:45:22 +0000 |
---|---|---|
committer | Conrad Ludgate <conradludgate@gmail.com> | 2021-11-21 10:23:52 +0000 |
commit | ecc304eba31d14617b4cccdfdf51e444368b8925 (patch) | |
tree | c9d7cef2fc8bf7fdf2ca79907624b093506cac16 /src | |
parent | de9d9e9ecaed979ea7793915dba96fddc4b0332d (diff) |
feat: allow for current_dir failure
Diffstat (limited to 'src')
-rw-r--r-- | src/file/source/file.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/file/source/file.rs b/src/file/source/file.rs index 64126d0..c3b5cd9 100644 --- a/src/file/source/file.rs +++ b/src/file/source/file.rs @@ -103,11 +103,10 @@ where let (filename, format) = self.find_file(format_hint)?; // Attempt to use a relative path for the URI - let base = env::current_dir()?; - let uri = match path_relative_from(&filename, &base) { - Some(value) => value, - None => filename.clone(), - }; + let uri = env::current_dir() + .ok() + .and_then(|base| path_relative_from(&filename, &base)) + .unwrap_or_else(|| filename.clone()); // Read contents from file let mut file = fs::File::open(filename)?; |