Skip to content

Commit 15e40d0

Browse files
authored
fix: Deno 2 permissions system update for ENV (#492)
Updates usages of of `Deno.errors.PermissionDenied` to also support Deno v2's new `Deno.errors.NotCapable`. Fixes #491
1 parent 9dea70a commit 15e40d0

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

connection/connection_params.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,10 @@ export function createParams(
420420
try {
421421
pgEnv = getPgEnv();
422422
} catch (e) {
423-
if (e instanceof Deno.errors.PermissionDenied) {
423+
// In Deno v1, Deno permission errors resulted in a Deno.errors.PermissionDenied exception. In Deno v2, a new
424+
// Deno.errors.NotCapable exception was added to replace this. The "in" check makes this code safe for both Deno
425+
// 1 and Deno 2
426+
if (e instanceof Deno.errors.PermissionDenied || ('NotCapable' in Deno.errors && e instanceof Deno.errors.NotCapable)) {
424427
has_env_access = false;
425428
} else {
426429
throw e;

tests/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let DEV_MODE: string | undefined;
1515
try {
1616
DEV_MODE = Deno.env.get("DENO_POSTGRES_DEVELOPMENT");
1717
} catch (e) {
18-
if (e instanceof Deno.errors.PermissionDenied) {
18+
if (e instanceof Deno.errors.PermissionDenied || ('NotCapable' in Deno.errors && e instanceof Deno.errors.NotCapable)) {
1919
throw new Error(
2020
"You need to provide ENV access in order to run the test suite",
2121
);

0 commit comments

Comments
 (0)