Repository: denoland/deno_core
Pull request #893 (2024-09-04 14:26:26)

feat: add NotCapable error, remove PermissionDenied

codecov-commenter: ## [Codecov](https://app.codecov.io/gh/denoland/deno_core/pull/893?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=denoland) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 81.90%. Comparing base [(`0c7f83e`)](https://app.codecov.io/gh/denoland/deno_core/commit/0c7f83ea8daabe8f541fc93ae97529dc446f5f24?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=denoland) to head [(`86a243f`)](https://app.codecov.io/gh/denoland/deno_core/commit/86a243f13477489e8f4d788c210f53d5f4d66104?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=denoland).
> Report is 113 commits behind head on main.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #893      +/-   ##
==========================================
+ Coverage   81.43%   81.90%   +0.46%     
==========================================
  Files          97       98       +1     
  Lines       23877    24929    +1052     
==========================================
+ Hits        19445    20417     +972     
- Misses       4432     4512      +80     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/denoland/deno_core/pull/893?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=denoland).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=denoland).


Patch:
diff --git a/core/01_core.js b/core/01_core.js
index ea79449..9251a32 100644
--- a/core/01_core.js
+++ b/core/01_core.js
@@ -313,7 +313,7 @@
     });
   }
 
-  // Some "extensions" rely on "BadResource", "Interrupted", "PermissionDenied"
+  // Some "extensions" rely on "BadResource", "Interrupted", "NotCapable"
   // errors in the JS code (eg. "deno_net") so they are provided in "Deno.core"
   // but later reexported on "Deno.errors"
   class BadResource extends Error {
@@ -332,17 +332,17 @@
   }
   const InterruptedPrototype = Interrupted.prototype;
 
-  class PermissionDenied extends Error {
+  class NotCapable extends Error {
     constructor(msg) {
       super(msg);
-      this.name = "PermissionDenied";
+      this.name = "NotCapable";
     }
   }
-  const PermissionDeniedPrototype = PermissionDenied.prototype;
+  const NotCapablePrototype = NotCapable.prototype;
 
   registerErrorClass("BadResource", BadResource);
   registerErrorClass("Interrupted", Interrupted);
-  registerErrorClass("PermissionDenied", PermissionDenied);
+  registerErrorClass("NotCapable", NotCapable);
 
   const promiseHooks = [
     [], // init
@@ -656,8 +656,8 @@
     BadResourcePrototype,
     Interrupted,
     InterruptedPrototype,
-    PermissionDenied,
-    PermissionDeniedPrototype,
+    NotCapable,
+    NotCapablePrototype,
     refOpPromise,
     unrefOpPromise,
     setReportExceptionCallback,
diff --git a/core/core.d.ts b/core/core.d.ts
index c452f6b..bc57cb7 100644
--- a/core/core.d.ts
+++ b/core/core.d.ts
@@ -263,8 +263,8 @@ export namespace core {
   export const BadResourcePrototype: typeof BadResource.prototype;
   export class Interrupted extends Error {}
   export const InterruptedPrototype: typeof Interrupted.prototype;
-  export class PermissionDenied extends Error {}
-  export const PermissionDeniedPrototype: typeof PermissionDenied.prototype;
+  export class NotCapable extends Error {}
+  export const NotCapablePrototype: typeof NotCapable.prototype;
 
   function serialize(
     value: any,
diff --git a/core/runtime/snapshot.rs b/core/runtime/snapshot.rs
index 7fc5d05..7a834af 100644
--- a/core/runtime/snapshot.rs
+++ b/core/runtime/snapshot.rs
@@ -29,7 +29,7 @@ pub(crate) struct V8Snapshot(pub(crate) &'static [u8]);
 
 pub(crate) fn deconstruct(
   slice: &'static [u8],
-) -> (V8Snapshot, SerializableSnapshotSidecarData) {
+) -> (V8Snapshot, SerializableSnapshotSidecarData<'static>) {
   let len =
     usize::from_le_bytes(slice[slice.len() - ULEN..].try_into().unwrap());
   let data = SerializableSnapshotSidecarData::from_slice(


Test patch:
diff --git a/testing/integration/ts_types/which.ts b/testing/integration/ts_types/which.ts
index 656be46..9ddae59 100644
--- a/testing/integration/ts_types/which.ts
+++ b/testing/integration/ts_types/which.ts
@@ -16,7 +16,7 @@ declare namespace Deno {
     function get(string);
   }
   namespace errors {
-    class PermissionDenied {}
+    class NotCapable {}
   }
   namespace build {
     const os: string;
@@ -93,7 +93,7 @@ async function pathMatches(
     const result = await environment.stat(path);
     return result.isFile;
   } catch (err) {
-    if (err instanceof Deno.errors.PermissionDenied) {
+    if (err instanceof Deno.errors.NotCapable) {
       throw err;
     }
     return false;
@@ -136,7 +136,7 @@ function pathMatchesSync(
     const result = environment.statSync(path);
     return result.isFile;
   } catch (err) {
-    if (err instanceof Deno.errors.PermissionDenied) {
+    if (err instanceof Deno.errors.NotCapable) {
       throw err;
     }
     return false;