diff options
author | Luca Casonato <hello@lcas.dev> | 2024-09-10 20:12:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-10 11:12:24 -0700 |
commit | 7bfcb4dd10d31f5f9566c90a28449c0951f3a48e (patch) | |
tree | fca0dec6e98118418f1712c6e8451a04c7e89988 /runtime | |
parent | be5419d479fcae16c8a07dec00ce11b532b7996a (diff) |
feat(cli): use NotCapable error for permission errors (#25431)
Closes #7394
---------
Co-authored-by: snek <snek@deno.com>
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/js/01_errors.js | 10 | ||||
-rw-r--r-- | runtime/js/99_main.js | 1 | ||||
-rw-r--r-- | runtime/ops/process.rs | 2 | ||||
-rw-r--r-- | runtime/permissions/lib.rs | 7 |
4 files changed, 13 insertions, 7 deletions
diff --git a/runtime/js/01_errors.js b/runtime/js/01_errors.js index bfcb540e2..ea567a5d0 100644 --- a/runtime/js/01_errors.js +++ b/runtime/js/01_errors.js @@ -1,7 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { core, primordials } from "ext:core/mod.js"; -const { BadResource, Interrupted, PermissionDenied } = core; +const { BadResource, Interrupted, NotCapable } = core; const { Error } = primordials; class NotFound extends Error { @@ -116,6 +116,13 @@ class Busy extends Error { } } +class PermissionDenied extends Error { + constructor(msg) { + super(msg); + this.name = "PermissionDenied"; + } +} + class NotSupported extends Error { constructor(msg) { super(msg); @@ -176,6 +183,7 @@ const errors = { IsADirectory, NetworkUnreachable, NotADirectory, + NotCapable, }; export { errors }; diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index f81ab3d8f..4b17635bb 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -294,6 +294,7 @@ core.registerErrorClass("NotConnected", errors.NotConnected); core.registerErrorClass("AddrInUse", errors.AddrInUse); core.registerErrorClass("AddrNotAvailable", errors.AddrNotAvailable); core.registerErrorClass("BrokenPipe", errors.BrokenPipe); +core.registerErrorClass("PermissionDenied", errors.PermissionDenied); core.registerErrorClass("AlreadyExists", errors.AlreadyExists); core.registerErrorClass("InvalidData", errors.InvalidData); core.registerErrorClass("TimedOut", errors.TimedOut); diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index c2fa212d3..d7058a053 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -609,7 +609,7 @@ fn check_run_permission( // we don't allow users to launch subprocesses with any LD_ or DYLD_* // env vars set because this allows executing code (ex. LD_PRELOAD) return Err(deno_core::error::custom_error( - "PermissionDenied", + "NotCapable", format!( "Requires --allow-all permissions to spawn subprocess with {} environment variable{}.", env_var_names.join(", "), diff --git a/runtime/permissions/lib.rs b/runtime/permissions/lib.rs index c5cfbff70..36750ae38 100644 --- a/runtime/permissions/lib.rs +++ b/runtime/permissions/lib.rs @@ -144,7 +144,7 @@ impl PermissionState { name ) }; - custom_error("PermissionDenied", msg) + custom_error("NotCapable", msg) } /// Check the permission state. bool is whether a prompt was issued. @@ -1999,10 +1999,7 @@ fn parse_run_list( } fn escalation_error() -> AnyError { - custom_error( - "PermissionDenied", - "Can't escalate parent thread permissions", - ) + custom_error("NotCapable", "Can't escalate parent thread permissions") } #[derive(Debug, Eq, PartialEq)] |