Skip to content

Commit

Permalink
refactor(runtime): align error messages
Browse files Browse the repository at this point in the history
Aligns the error messages in the runtime folder to be in-line with the
Deno style guide.

denoland#25269
  • Loading branch information
irbull committed Sep 10, 2024
1 parent be5419d commit a3bc938
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 35 deletions.
8 changes: 4 additions & 4 deletions runtime/js/10_permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class PermissionStatus extends EventTarget {
*/
constructor(status = null, key = null) {
if (key != illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
throw new TypeError("Illegal constructor");
}
super();
this.#status = status;
Expand Down Expand Up @@ -194,7 +194,7 @@ function formDescriptor(desc) {
class Permissions {
constructor(key = null) {
if (key != illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
throw new TypeError("Illegal constructor");
}
}

Expand All @@ -209,7 +209,7 @@ class Permissions {
querySync(desc) {
if (!isValidDescriptor(desc)) {
throw new TypeError(
`The provided value "${desc?.name}" is not a valid permission name.`,
`The provided value "${desc?.name}" is not a valid permission name`,
);
}

Expand All @@ -230,7 +230,7 @@ class Permissions {
revokeSync(desc) {
if (!isValidDescriptor(desc)) {
throw new TypeError(
`The provided value "${desc?.name}" is not a valid permission name.`,
`The provided value "${desc?.name}" is not a valid permission name`,
);
}

Expand Down
26 changes: 13 additions & 13 deletions runtime/js/40_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Process {

async output() {
if (!this.stdout) {
throw new TypeError("stdout was not piped");
throw new TypeError("Cannot collect output: 'stdout' is not piped");
}
try {
return await readAll(this.stdout);
Expand All @@ -112,7 +112,7 @@ class Process {

async stderrOutput() {
if (!this.stderr) {
throw new TypeError("stderr was not piped");
throw new TypeError("Cannot collect output: 'stderr' is not piped");
}
try {
return await readAll(this.stderr);
Expand Down Expand Up @@ -235,23 +235,23 @@ class ChildProcess {
#stdin = null;
get stdin() {
if (this.#stdin == null) {
throw new TypeError("stdin is not piped");
throw new TypeError("Cannot get 'stdin': 'stdin' is not piped");
}
return this.#stdin;
}

#stdout = null;
get stdout() {
if (this.#stdout == null) {
throw new TypeError("stdout is not piped");
throw new TypeError("Cannot get 'stdout': 'stdout' is not piped");
}
return this.#stdout;
}

#stderr = null;
get stderr() {
if (this.#stderr == null) {
throw new TypeError("stderr is not piped");
throw new TypeError("Cannot get 'stderr': 'stderr' is not piped");
}
return this.#stderr;
}
Expand All @@ -267,7 +267,7 @@ class ChildProcess {
extraPipeRids,
} = null) {
if (key !== illegalConstructorKey) {
throw new TypeError("Illegal constructor.");
throw new TypeError("Illegal constructor");
}

this.#rid = rid;
Expand Down Expand Up @@ -307,12 +307,12 @@ class ChildProcess {
async output() {
if (this.#stdout?.locked) {
throw new TypeError(
"Can't collect output because stdout is locked",
"Cannot collect output: 'stdout' is locked",
);
}
if (this.#stderr?.locked) {
throw new TypeError(
"Can't collect output because stderr is locked",
"Cannot collect output: 'stderr' is locked",
);
}

Expand All @@ -328,13 +328,13 @@ class ChildProcess {
signal: status.signal,
get stdout() {
if (stdout == null) {
throw new TypeError("stdout is not piped");
throw new TypeError("Cannot get 'stdout': 'stdout' is not piped");
}
return stdout;
},
get stderr() {
if (stderr == null) {
throw new TypeError("stderr is not piped");
throw new TypeError("Cannot get 'stderr': 'stderr' is not piped");
}
return stderr;
},
Expand All @@ -343,7 +343,7 @@ class ChildProcess {

kill(signo = "SIGTERM") {
if (this.#waitComplete) {
throw new TypeError("Child process has already terminated.");
throw new TypeError("Child process has already terminated");
}
op_spawn_kill(this.#rid, signo);
}
Expand Down Expand Up @@ -421,13 +421,13 @@ function spawnSync(command, {
signal: result.status.signal,
get stdout() {
if (result.stdout == null) {
throw new TypeError("stdout is not piped");
throw new TypeError("Cannot get 'stdout': 'stdout' is not piped");
}
return result.stdout;
},
get stderr() {
if (result.stderr == null) {
throw new TypeError("stderr is not piped");
throw new TypeError("Cannot get 'stderr': 'stderr' is not piped");
}
return result.stderr;
},
Expand Down
12 changes: 6 additions & 6 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ import {
import { SymbolDispose, SymbolMetadata } from "ext:deno_web/00_infra.js";
// deno-lint-ignore prefer-primordials
if (Symbol.metadata) {
throw "V8 supports Symbol.metadata now, no need to shim it!";
throw "V8 supports Symbol.metadata now, no need to shim it";
}
ObjectDefineProperties(Symbol, {
dispose: {
Expand Down Expand Up @@ -228,7 +228,7 @@ let loadedMainWorkerScript = false;

function importScripts(...urls) {
if (op_worker_get_type() === "module") {
throw new TypeError("Can't import scripts in a module worker.");
throw new TypeError("Cannot import scripts in a module worker");
}

const baseUrl = location.getLocationHref();
Expand All @@ -237,7 +237,7 @@ function importScripts(...urls) {
return new url.URL(scriptUrl, baseUrl ?? undefined).href;
} catch {
throw new DOMException(
"Failed to parse URL.",
`Failed to parse URL: ${scriptUrl}`,
"SyntaxError",
);
}
Expand Down Expand Up @@ -719,7 +719,7 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
return jupyterNs;
}
throw new Error(
"Deno.jupyter is only available in `deno jupyter` subcommand.",
"Deno.jupyter is only available in `deno jupyter` subcommand",
);
},
set(val) {
Expand Down Expand Up @@ -747,7 +747,7 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
// https://github.com/tc39/proposal-temporal/pull/2895
// https://github.com/tc39/proposal-temporal/pull/2914
if (typeof Temporal.Instant.fromEpochSeconds === "undefined") {
throw "V8 removes obsoleted Temporal API now, no need to delete them!";
throw "V8 removes obsoleted Temporal API now, no need to delete them";
}
delete Temporal.Instant.fromEpochSeconds;
delete Temporal.Instant.fromEpochMicroseconds;
Expand Down Expand Up @@ -890,7 +890,7 @@ function bootstrapWorkerRuntime(
// https://github.com/tc39/proposal-temporal/pull/2895
// https://github.com/tc39/proposal-temporal/pull/2914
if (typeof Temporal.Instant.fromEpochSeconds === "undefined") {
throw "V8 removes obsoleted Temporal API now, no need to delete them!";
throw "V8 removes obsoleted Temporal API now, no need to delete them";
}
delete Temporal.Instant.fromEpochSeconds;
delete Temporal.Instant.fromEpochMicroseconds;
Expand Down
56 changes: 46 additions & 10 deletions tests/unit/command_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,16 @@ Deno.test(
});
const child = command.spawn();

assertThrows(() => child.stdout, TypeError, "stdout is not piped");
assertThrows(() => child.stderr, TypeError, "stderr is not piped");
assertThrows(
() => child.stdout,
TypeError,
"Cannot get 'stdout': 'stdout' is not piped",
);
assertThrows(
() => child.stderr,
TypeError,
"Cannot get 'stderr': 'stderr' is not piped",
);

const msg = new TextEncoder().encode("hello");
const writer = child.stdin.getWriter();
Expand All @@ -99,9 +107,21 @@ Deno.test(
});
const child = command.spawn();

assertThrows(() => child.stdin, TypeError, "stdin is not piped");
assertThrows(() => child.stdout, TypeError, "stdout is not piped");
assertThrows(() => child.stderr, TypeError, "stderr is not piped");
assertThrows(
() => child.stdin,
TypeError,
"Cannot get 'stdin': 'stdin' is not piped",
);
assertThrows(
() => child.stdout,
TypeError,
"Cannot get 'stdout': 'stdout' is not piped",
);
assertThrows(
() => child.stderr,
TypeError,
"Cannot get 'stderr': 'stderr' is not piped",
);

await child.status;
},
Expand All @@ -120,8 +140,16 @@ Deno.test(
});
const child = command.spawn();

assertThrows(() => child.stdin, TypeError, "stdin is not piped");
assertThrows(() => child.stderr, TypeError, "stderr is not piped");
assertThrows(
() => child.stdin,
TypeError,
"Cannot get 'stdin': 'stdin' is not piped",
);
assertThrows(
() => child.stderr,
TypeError,
"Cannot get 'stderr': 'stderr' is not piped",
);

const readable = child.stdout.pipeThrough(new TextDecoderStream());
const reader = readable.getReader();
Expand Down Expand Up @@ -154,8 +182,16 @@ Deno.test(
});
const child = command.spawn();

assertThrows(() => child.stdin, TypeError, "stdin is not piped");
assertThrows(() => child.stdout, TypeError, "stdout is not piped");
assertThrows(
() => child.stdin,
TypeError,
"Cannot get 'stdin': 'stdin' is not piped",
);
assertThrows(
() => child.stdout,
TypeError,
"Cannot get 'stdout': 'stdout' is not piped",
);

const readable = child.stderr.pipeThrough(new TextDecoderStream());
const reader = readable.getReader();
Expand Down Expand Up @@ -955,7 +991,7 @@ Deno.test(
assertThrows(
() => child.kill(),
TypeError,
"Child process has already terminated.",
"Child process has already terminated",
);
},
);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/permissions_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ Deno.test(function permissionQueryForReadReturnsSameStatusSync() {
});

Deno.test(function permissionsIllegalConstructor() {
assertThrows(() => new Deno.Permissions(), TypeError, "Illegal constructor.");
assertThrows(() => new Deno.Permissions(), TypeError, "Illegal constructor");
assertEquals(Deno.Permissions.length, 0);
});

Deno.test(function permissionStatusIllegalConstructor() {
assertThrows(
() => new Deno.PermissionStatus(),
TypeError,
"Illegal constructor.",
"Illegal constructor",
);
assertEquals(Deno.PermissionStatus.length, 0);
});
Expand Down

0 comments on commit a3bc938

Please sign in to comment.