diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/fs_util.rs | 4 | ||||
-rw-r--r-- | runtime/ops/runtime.rs | 5 | ||||
-rw-r--r-- | runtime/web_worker.rs | 5 | ||||
-rw-r--r-- | runtime/worker.rs | 5 |
4 files changed, 15 insertions, 4 deletions
diff --git a/runtime/fs_util.rs b/runtime/fs_util.rs index bf0735205..93286ecf3 100644 --- a/runtime/fs_util.rs +++ b/runtime/fs_util.rs @@ -1,6 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use deno_core::error::AnyError; +use deno_core::error::Context; pub use deno_core::normalize_path; use std::env::current_dir; use std::io::Error; @@ -24,7 +25,8 @@ pub fn resolve_from_cwd(path: &Path) -> Result<PathBuf, AnyError> { let resolved_path = if path.is_absolute() { path.to_owned() } else { - let cwd = current_dir().unwrap(); + let cwd = + current_dir().context("Failed to get current working directory")?; cwd.join(path) }; diff --git a/runtime/ops/runtime.rs b/runtime/ops/runtime.rs index d90e92593..a02bf4548 100644 --- a/runtime/ops/runtime.rs +++ b/runtime/ops/runtime.rs @@ -5,6 +5,7 @@ use crate::metrics::RuntimeMetrics; use crate::ops::UnstableChecker; use crate::permissions::Permissions; use deno_core::error::AnyError; +use deno_core::error::Context; use deno_core::serde_json::json; use deno_core::serde_json::Value; use deno_core::ModuleSpecifier; @@ -29,7 +30,9 @@ fn op_main_module( let main = state.borrow::<ModuleSpecifier>().to_string(); let main_url = deno_core::resolve_url_or_path(&main)?; if main_url.scheme() == "file" { - let main_path = std::env::current_dir().unwrap().join(main_url.to_string()); + let main_path = std::env::current_dir() + .context("Failed to get current working directory")? + .join(main_url.to_string()); state .borrow_mut::<Permissions>() .read diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 57c3909e1..cdc3d7e3d 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -8,6 +8,7 @@ use crate::ops; use crate::permissions::Permissions; use crate::tokio_util::create_basic_runtime; use deno_core::error::AnyError; +use deno_core::error::Context as ErrorContext; use deno_core::futures::channel::mpsc; use deno_core::futures::future::poll_fn; use deno_core::futures::future::FutureExt; @@ -320,7 +321,9 @@ impl WebWorker { /// Same as execute2() but the filename defaults to "$CWD/__anonymous__". pub fn execute(&mut self, js_source: &str) -> Result<(), AnyError> { - let path = env::current_dir().unwrap().join("__anonymous__"); + let path = env::current_dir() + .context("Failed to get current working directory")? + .join("__anonymous__"); let url = Url::from_file_path(path).unwrap(); self.js_runtime.execute(url.as_str(), js_source) } diff --git a/runtime/worker.rs b/runtime/worker.rs index 253725533..6de87f52e 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -8,6 +8,7 @@ use crate::metrics::RuntimeMetrics; use crate::ops; use crate::permissions::Permissions; use deno_core::error::AnyError; +use deno_core::error::Context as ErrorContext; use deno_core::futures::future::poll_fn; use deno_core::futures::future::FutureExt; use deno_core::futures::stream::StreamExt; @@ -201,7 +202,9 @@ impl MainWorker { /// Same as execute2() but the filename defaults to "$CWD/__anonymous__". pub fn execute(&mut self, js_source: &str) -> Result<(), AnyError> { - let path = env::current_dir().unwrap().join("__anonymous__"); + let path = env::current_dir() + .context("Failed to get current working directory")? + .join("__anonymous__"); let url = Url::from_file_path(path).unwrap(); self.js_runtime.execute(url.as_str(), js_source) } |