diff options
Diffstat (limited to 'runtime/permissions/lib.rs')
-rw-r--r-- | runtime/permissions/lib.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/runtime/permissions/lib.rs b/runtime/permissions/lib.rs index b0fa9eb10..55a94d909 100644 --- a/runtime/permissions/lib.rs +++ b/runtime/permissions/lib.rs @@ -12,6 +12,7 @@ use deno_core::serde::Deserialize; use deno_core::serde::Deserializer; use deno_core::serde::Serialize; use deno_core::serde_json; +use deno_core::unsync::sync::AtomicFlag; use deno_core::url; use deno_core::url::Url; use deno_core::ModuleSpecifier; @@ -132,14 +133,20 @@ impl PermissionState { } fn error(name: &str, info: impl FnOnce() -> Option<String>) -> AnyError { - custom_error( - "PermissionDenied", + let msg = if is_standalone() { + format!( + "Requires {}, specify the required permissions during compilation using `deno compile --allow-{}`", + Self::fmt_access(name, info), + name + ) + } else { format!( "Requires {}, run again with the --allow-{} flag", Self::fmt_access(name, info), name - ), - ) + ) + }; + custom_error("PermissionDenied", msg) } /// Check the permission state. bool is whether a prompt was issued. @@ -2313,6 +2320,16 @@ pub fn create_child_permissions( Ok(worker_perms) } +static IS_STANDALONE: AtomicFlag = AtomicFlag::lowered(); + +pub fn mark_standalone() { + IS_STANDALONE.raise(); +} + +pub fn is_standalone() -> bool { + IS_STANDALONE.is_raised() +} + #[cfg(test)] mod tests { use super::*; |