mirror of
https://github.com/denoland/deno.git
synced 2024-12-18 05:14:21 -05:00
feat(permission): separate PermissionDeniedError to Retryable and Fatal (#27282)
This commit separates `PermissionDeniedError` into two kinds; `Retryable` and `Fatal`. The existing `PermissionDeniedError`s fall into `Retryable`, since permission errors can be resolved by retrying with proper permissions in Deno CLI. The motivation of adding `Fatal` is that in some environments some operations are just disabled; for instance, in Deno Deploy, any write operations to filesystem can never be granted, in which case `Fatal` kind becomes useful. Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
f9add94e17
commit
c56274285d
1 changed files with 11 additions and 8 deletions
|
@ -39,10 +39,11 @@ pub use prompter::PromptCallback;
|
|||
pub use prompter::PromptResponse;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[error("Requires {access}, {}", format_permission_error(.name))]
|
||||
pub struct PermissionDeniedError {
|
||||
pub access: String,
|
||||
pub name: &'static str,
|
||||
pub enum PermissionDeniedError {
|
||||
#[error("Requires {access}, {}", format_permission_error(.name))]
|
||||
Retryable { access: String, name: &'static str },
|
||||
#[error("Requires {access}, which cannot be granted in this environment")]
|
||||
Fatal { access: String },
|
||||
}
|
||||
|
||||
fn format_permission_error(name: &'static str) -> String {
|
||||
|
@ -144,11 +145,11 @@ impl PermissionState {
|
|||
)
|
||||
}
|
||||
|
||||
fn error(
|
||||
fn retryable_error(
|
||||
name: &'static str,
|
||||
info: impl FnOnce() -> Option<String>,
|
||||
) -> PermissionDeniedError {
|
||||
PermissionDeniedError {
|
||||
PermissionDeniedError::Retryable {
|
||||
access: Self::fmt_access(name, info),
|
||||
name,
|
||||
}
|
||||
|
@ -201,10 +202,12 @@ impl PermissionState {
|
|||
Self::log_perm_access(name, info);
|
||||
(Ok(()), true, true)
|
||||
}
|
||||
PromptResponse::Deny => (Err(Self::error(name, info)), true, false),
|
||||
PromptResponse::Deny => {
|
||||
(Err(Self::retryable_error(name, info)), true, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (Err(Self::error(name, info)), false, false),
|
||||
_ => (Err(Self::retryable_error(name, info)), false, false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue