Skip to content

Commit

Permalink
Merge pull request rscarson#263 from rscarson/rscarson-patch-1
Browse files Browse the repository at this point in the history
Expose PermissionDenied
  • Loading branch information
rscarson authored Nov 16, 2024
2 parents 3b05e9a + 21ccd38 commit 111bf75
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/ext/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ pub use options::WebOptions;
mod permissions;
pub(crate) use permissions::PermissionsContainer;
pub use permissions::{
AllowlistWebPermissions, DefaultWebPermissions, SystemsPermissionKind, WebPermissions,
AllowlistWebPermissions, DefaultWebPermissions, PermissionDenied, SystemsPermissionKind,
WebPermissions,
};

extension!(
Expand Down
5 changes: 5 additions & 0 deletions src/ext/web/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ use std::{
/// This type is needed since `deno_permissions` does not expose any way to
/// externally create a `PermissionCheckError`
pub struct PermissionDenied {
/// The resource being accessed
pub access: String,

/// The reason or kind of denial
pub name: &'static str,
}
impl PermissionDenied {
/// Create a new error
pub fn new(access: impl ToString, reason: &'static str) -> Self {
Self {
access: access.to_string(),
name: reason,
}
}

/// Resolved to an Err(Self) with a generic "Not Allowed" message
pub fn oops<T>(access: impl ToString) -> Result<T, Self> {
Err(Self::new(access, "Not Allowed"))
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ pub use ext::node::RustyResolver;

#[cfg(feature = "web")]
pub use ext::web::{
AllowlistWebPermissions, DefaultWebPermissions, SystemsPermissionKind, WebOptions,
WebPermissions,
AllowlistWebPermissions, DefaultWebPermissions, PermissionDenied, SystemsPermissionKind,
WebOptions, WebPermissions,
};
pub use ext::ExtensionOptions;

Expand Down

0 comments on commit 111bf75

Please sign in to comment.