Skip to content

Commit

Permalink
fix: Deno 2 permissions system update for ENV
Browse files Browse the repository at this point in the history
Updates usages of of `Deno.errors.PermissionDenied` to also support Deno v2's new `Deno.errors.NotCapable`.

Fixes denodrivers#491
  • Loading branch information
allout58 committed Oct 14, 2024
1 parent c627326 commit eb9e403
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion connection/connection_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ export function createParams(
try {
pgEnv = getPgEnv();
} catch (e) {
if (e instanceof Deno.errors.PermissionDenied) {
// In Deno v1, Deno permission errors resulted in a Deno.errors.PermissionDenied exception. In Deno v2, a new
// Deno.errors.NotCapable exception was added to replace this. The "in" check makes this code safe for both Deno
// 1 and Deno 2
if (e instanceof Deno.errors.PermissionDenied || ('NotCapable' in Deno.errors && e instanceof Deno.errors.NotCapable)) {
has_env_access = false;
} else {
throw e;
Expand Down
2 changes: 1 addition & 1 deletion tests/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let DEV_MODE: string | undefined;
try {
DEV_MODE = Deno.env.get("DENO_POSTGRES_DEVELOPMENT");
} catch (e) {
if (e instanceof Deno.errors.PermissionDenied) {
if (e instanceof Deno.errors.PermissionDenied || ('NotCapable' in Deno.errors && e instanceof Deno.errors.NotCapable)) {
throw new Error(
"You need to provide ENV access in order to run the test suite",
);
Expand Down

0 comments on commit eb9e403

Please sign in to comment.