Skip to content

Commit

Permalink
dx: descriptive permission errors (denoland/deno#3808)
Browse files Browse the repository at this point in the history
Before:
```
▶ target/debug/deno https://deno.land/examples/echo_server.ts
error: Uncaught PermissionDenied: run again with the --allow-net flag
► $deno$/dispatch_json.ts:40:11
    at DenoError ($deno$/errors.ts:20:5)
    at unwrapResponse ($deno$/dispatch_json.ts:40:11)
    at sendSync ($deno$/dispatch_json.ts:67:10)
    at listen ($deno$/net.ts:170:15)
    at https://deno.land/examples/echo_server.ts:4:23
```

```
▶ target/debug/deno --allow-read=/usr https://deno.land/examples/cat.ts /etc/passwd
error: Uncaught PermissionDenied: run again with the --allow-read flag
► $deno$/dispatch_json.ts:40:11
    at DenoError ($deno$/errors.ts:20:5)
    at unwrapResponse ($deno$/dispatch_json.ts:40:11)
    at sendAsync ($deno$/dispatch_json.ts:91:10)
```

After:
```
▶ target/debug/deno https://deno.land/examples/echo_server.ts
error: Uncaught PermissionDenied: network access to "0.0.0.0:8080", run again with the --allow-net flag
► $deno$/dispatch_json.ts:40:11
    at DenoError ($deno$/errors.ts:20:5)
    at unwrapResponse ($deno$/dispatch_json.ts:40:11)
    at sendSync ($deno$/dispatch_json.ts:67:10)
    at listen ($deno$/net.ts:170:15)
    at https://deno.land/examples/echo_server.ts:4:23
```

```
▶ target/debug/deno --allow-read=/usr https://deno.land/examples/cat.ts /etc/passwd
error: Uncaught PermissionDenied: read access to "/etc/passwd", run again with the --allow-read flag
► $deno$/dispatch_json.ts:40:11
    at DenoError ($deno$/errors.ts:20:5)
    at unwrapResponse ($deno$/dispatch_json.ts:40:11)
    at sendAsync ($deno$/dispatch_json.ts:91:10)
```
  • Loading branch information
bartlomieju authored and caspervonb committed Jan 31, 2021
1 parent 71e80c6 commit 1347038
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion fs/empty_dir_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { test } from "../testing/mod.ts";
import {
assertEquals,
assertStrContains,
assertThrows,
assertThrowsAsync
} from "../testing/asserts.ts";
Expand Down Expand Up @@ -227,7 +228,7 @@ test(async function emptyDirPermission(): Promise<void> {

const output = await Deno.readAll(stdout);

assertEquals(new TextDecoder().decode(output), s.output);
assertStrContains(new TextDecoder().decode(output), s.output);
}
} catch (err) {
await Deno.remove(testfolder, { recursive: true });
Expand Down
4 changes: 2 additions & 2 deletions fs/exists_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { assertEquals, assertStrContains } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { exists, existsSync } from "./exists.ts";

Expand Down Expand Up @@ -134,7 +134,7 @@ test(async function existsPermission(): Promise<void> {

const output = await Deno.readAll(stdout);

assertEquals(new TextDecoder().decode(output), s.output);
assertStrContains(new TextDecoder().decode(output), s.output);
}

// done
Expand Down
6 changes: 3 additions & 3 deletions http/file_server_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assert, assertEquals } from "../testing/asserts.ts";
import { assert, assertEquals, assertStrContains } from "../testing/asserts.ts";
import { BufReader } from "../io/bufio.ts";
import { TextProtoReader } from "../textproto/mod.ts";

Expand Down Expand Up @@ -109,8 +109,8 @@ test(async function servePermissionDenied(): Promise<void> {

try {
await fetch("http://localhost:4500/");
assertEquals(
await errReader.readLine(),
assertStrContains(
(await errReader.readLine()) as string,
"run again with the --allow-read flag"
);
} finally {
Expand Down
4 changes: 2 additions & 2 deletions manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ When this program is started, it throws PermissionDenied error.

```shell
$ deno https://deno.land/std/examples/echo_server.ts
error: Uncaught PermissionDenied: run again with the --allow-net flag
error: Uncaught PermissionDenied: network access to "0.0.0.0:8080", run again with the --allow-net flag
$deno$/dispatch_json.ts:40:11
at DenoError ($deno$/errors.ts:20:5)
...
Expand Down Expand Up @@ -329,7 +329,7 @@ This is an example to restrict file system access by whitelist.

```shell
$ deno --allow-read=/usr https://deno.land/std/examples/cat.ts /etc/passwd
error: Uncaught PermissionDenied: run again with the --allow-read flag
error: Uncaught PermissionDenied: read access to "/etc/passwd", run again with the --allow-read flag
$deno$/dispatch_json.ts:40:11
at DenoError ($deno$/errors.ts:20:5)
...
Expand Down

0 comments on commit 1347038

Please sign in to comment.