mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
refactor(runtime): align error messages (#25563)
Aligns the error messages in the runtime folder to be in-line with the Deno style guide. https://github.com/denoland/deno/issues/25269
This commit is contained in:
parent
7477c2d706
commit
606b7b17c6
5 changed files with 71 additions and 35 deletions
|
@ -95,7 +95,7 @@ class PermissionStatus extends EventTarget {
|
||||||
*/
|
*/
|
||||||
constructor(status = null, key = null) {
|
constructor(status = null, key = null) {
|
||||||
if (key != illegalConstructorKey) {
|
if (key != illegalConstructorKey) {
|
||||||
throw new TypeError("Illegal constructor.");
|
throw new TypeError("Illegal constructor");
|
||||||
}
|
}
|
||||||
super();
|
super();
|
||||||
this.#status = status;
|
this.#status = status;
|
||||||
|
@ -194,7 +194,7 @@ function formDescriptor(desc) {
|
||||||
class Permissions {
|
class Permissions {
|
||||||
constructor(key = null) {
|
constructor(key = null) {
|
||||||
if (key != illegalConstructorKey) {
|
if (key != illegalConstructorKey) {
|
||||||
throw new TypeError("Illegal constructor.");
|
throw new TypeError("Illegal constructor");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ class Permissions {
|
||||||
querySync(desc) {
|
querySync(desc) {
|
||||||
if (!isValidDescriptor(desc)) {
|
if (!isValidDescriptor(desc)) {
|
||||||
throw new TypeError(
|
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`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ class Permissions {
|
||||||
revokeSync(desc) {
|
revokeSync(desc) {
|
||||||
if (!isValidDescriptor(desc)) {
|
if (!isValidDescriptor(desc)) {
|
||||||
throw new TypeError(
|
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`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ class Process {
|
||||||
|
|
||||||
async output() {
|
async output() {
|
||||||
if (!this.stdout) {
|
if (!this.stdout) {
|
||||||
throw new TypeError("stdout was not piped");
|
throw new TypeError("Cannot collect output: 'stdout' is not piped");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return await readAll(this.stdout);
|
return await readAll(this.stdout);
|
||||||
|
@ -112,7 +112,7 @@ class Process {
|
||||||
|
|
||||||
async stderrOutput() {
|
async stderrOutput() {
|
||||||
if (!this.stderr) {
|
if (!this.stderr) {
|
||||||
throw new TypeError("stderr was not piped");
|
throw new TypeError("Cannot collect output: 'stderr' is not piped");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return await readAll(this.stderr);
|
return await readAll(this.stderr);
|
||||||
|
@ -241,7 +241,7 @@ class ChildProcess {
|
||||||
#stdin = null;
|
#stdin = null;
|
||||||
get stdin() {
|
get stdin() {
|
||||||
if (this.#stdin == null) {
|
if (this.#stdin == null) {
|
||||||
throw new TypeError("stdin is not piped");
|
throw new TypeError("Cannot get 'stdin': 'stdin' is not piped");
|
||||||
}
|
}
|
||||||
return this.#stdin;
|
return this.#stdin;
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ class ChildProcess {
|
||||||
#stdout = null;
|
#stdout = null;
|
||||||
get stdout() {
|
get stdout() {
|
||||||
if (this.#stdout == null) {
|
if (this.#stdout == null) {
|
||||||
throw new TypeError("stdout is not piped");
|
throw new TypeError("Cannot get 'stdout': 'stdout' is not piped");
|
||||||
}
|
}
|
||||||
return this.#stdout;
|
return this.#stdout;
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ class ChildProcess {
|
||||||
#stderr = null;
|
#stderr = null;
|
||||||
get stderr() {
|
get stderr() {
|
||||||
if (this.#stderr == null) {
|
if (this.#stderr == null) {
|
||||||
throw new TypeError("stderr is not piped");
|
throw new TypeError("Cannot get 'stderr': 'stderr' is not piped");
|
||||||
}
|
}
|
||||||
return this.#stderr;
|
return this.#stderr;
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,7 @@ class ChildProcess {
|
||||||
extraPipeRids,
|
extraPipeRids,
|
||||||
} = null) {
|
} = null) {
|
||||||
if (key !== illegalConstructorKey) {
|
if (key !== illegalConstructorKey) {
|
||||||
throw new TypeError("Illegal constructor.");
|
throw new TypeError("Illegal constructor");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#rid = rid;
|
this.#rid = rid;
|
||||||
|
@ -313,12 +313,12 @@ class ChildProcess {
|
||||||
async output() {
|
async output() {
|
||||||
if (this.#stdout?.locked) {
|
if (this.#stdout?.locked) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
"Can't collect output because stdout is locked",
|
"Cannot collect output: 'stdout' is locked",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (this.#stderr?.locked) {
|
if (this.#stderr?.locked) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
"Can't collect output because stderr is locked",
|
"Cannot collect output: 'stderr' is locked",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,13 +334,13 @@ class ChildProcess {
|
||||||
signal: status.signal,
|
signal: status.signal,
|
||||||
get stdout() {
|
get stdout() {
|
||||||
if (stdout == null) {
|
if (stdout == null) {
|
||||||
throw new TypeError("stdout is not piped");
|
throw new TypeError("Cannot get 'stdout': 'stdout' is not piped");
|
||||||
}
|
}
|
||||||
return stdout;
|
return stdout;
|
||||||
},
|
},
|
||||||
get stderr() {
|
get stderr() {
|
||||||
if (stderr == null) {
|
if (stderr == null) {
|
||||||
throw new TypeError("stderr is not piped");
|
throw new TypeError("Cannot get 'stderr': 'stderr' is not piped");
|
||||||
}
|
}
|
||||||
return stderr;
|
return stderr;
|
||||||
},
|
},
|
||||||
|
@ -349,7 +349,7 @@ class ChildProcess {
|
||||||
|
|
||||||
kill(signo = "SIGTERM") {
|
kill(signo = "SIGTERM") {
|
||||||
if (this.#waitComplete) {
|
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);
|
op_spawn_kill(this.#rid, signo);
|
||||||
}
|
}
|
||||||
|
@ -428,13 +428,13 @@ function spawnSync(command, {
|
||||||
signal: result.status.signal,
|
signal: result.status.signal,
|
||||||
get stdout() {
|
get stdout() {
|
||||||
if (result.stdout == null) {
|
if (result.stdout == null) {
|
||||||
throw new TypeError("stdout is not piped");
|
throw new TypeError("Cannot get 'stdout': 'stdout' is not piped");
|
||||||
}
|
}
|
||||||
return result.stdout;
|
return result.stdout;
|
||||||
},
|
},
|
||||||
get stderr() {
|
get stderr() {
|
||||||
if (result.stderr == null) {
|
if (result.stderr == null) {
|
||||||
throw new TypeError("stderr is not piped");
|
throw new TypeError("Cannot get 'stderr': 'stderr' is not piped");
|
||||||
}
|
}
|
||||||
return result.stderr;
|
return result.stderr;
|
||||||
},
|
},
|
||||||
|
|
|
@ -88,7 +88,7 @@ import {
|
||||||
import { SymbolDispose, SymbolMetadata } from "ext:deno_web/00_infra.js";
|
import { SymbolDispose, SymbolMetadata } from "ext:deno_web/00_infra.js";
|
||||||
// deno-lint-ignore prefer-primordials
|
// deno-lint-ignore prefer-primordials
|
||||||
if (Symbol.metadata) {
|
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, {
|
ObjectDefineProperties(Symbol, {
|
||||||
dispose: {
|
dispose: {
|
||||||
|
@ -230,7 +230,7 @@ let loadedMainWorkerScript = false;
|
||||||
|
|
||||||
function importScripts(...urls) {
|
function importScripts(...urls) {
|
||||||
if (op_worker_get_type() === "module") {
|
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();
|
const baseUrl = location.getLocationHref();
|
||||||
|
@ -239,7 +239,7 @@ function importScripts(...urls) {
|
||||||
return new url.URL(scriptUrl, baseUrl ?? undefined).href;
|
return new url.URL(scriptUrl, baseUrl ?? undefined).href;
|
||||||
} catch {
|
} catch {
|
||||||
throw new DOMException(
|
throw new DOMException(
|
||||||
"Failed to parse URL.",
|
`Failed to parse URL: ${scriptUrl}`,
|
||||||
"SyntaxError",
|
"SyntaxError",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -722,7 +722,7 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
|
||||||
return jupyterNs;
|
return jupyterNs;
|
||||||
}
|
}
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Deno.jupyter is only available in `deno jupyter` subcommand.",
|
"Deno.jupyter is only available in `deno jupyter` subcommand",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
set(val) {
|
set(val) {
|
||||||
|
@ -751,7 +751,7 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
|
||||||
// https://github.com/tc39/proposal-temporal/pull/2914
|
// https://github.com/tc39/proposal-temporal/pull/2914
|
||||||
// https://github.com/tc39/proposal-temporal/pull/2925
|
// https://github.com/tc39/proposal-temporal/pull/2925
|
||||||
if (typeof globalThis.Temporal.Instant.fromEpochSeconds === "undefined") {
|
if (typeof globalThis.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 globalThis.Temporal.Instant.fromEpochSeconds;
|
delete globalThis.Temporal.Instant.fromEpochSeconds;
|
||||||
delete globalThis.Temporal.Instant.fromEpochMicroseconds;
|
delete globalThis.Temporal.Instant.fromEpochMicroseconds;
|
||||||
|
@ -960,7 +960,7 @@ function bootstrapWorkerRuntime(
|
||||||
// https://github.com/tc39/proposal-temporal/pull/2914
|
// https://github.com/tc39/proposal-temporal/pull/2914
|
||||||
// https://github.com/tc39/proposal-temporal/pull/2925
|
// https://github.com/tc39/proposal-temporal/pull/2925
|
||||||
if (typeof globalThis.Temporal.Instant.fromEpochSeconds === "undefined") {
|
if (typeof globalThis.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 globalThis.Temporal.Instant.fromEpochSeconds;
|
delete globalThis.Temporal.Instant.fromEpochSeconds;
|
||||||
delete globalThis.Temporal.Instant.fromEpochMicroseconds;
|
delete globalThis.Temporal.Instant.fromEpochMicroseconds;
|
||||||
|
|
|
@ -73,8 +73,16 @@ Deno.test(
|
||||||
});
|
});
|
||||||
const child = command.spawn();
|
const child = command.spawn();
|
||||||
|
|
||||||
assertThrows(() => child.stdout, TypeError, "stdout is not piped");
|
assertThrows(
|
||||||
assertThrows(() => child.stderr, TypeError, "stderr is not piped");
|
() => 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 msg = new TextEncoder().encode("hello");
|
||||||
const writer = child.stdin.getWriter();
|
const writer = child.stdin.getWriter();
|
||||||
|
@ -99,9 +107,21 @@ Deno.test(
|
||||||
});
|
});
|
||||||
const child = command.spawn();
|
const child = command.spawn();
|
||||||
|
|
||||||
assertThrows(() => child.stdin, TypeError, "stdin is not piped");
|
assertThrows(
|
||||||
assertThrows(() => child.stdout, TypeError, "stdout is not piped");
|
() => child.stdin,
|
||||||
assertThrows(() => child.stderr, TypeError, "stderr is not piped");
|
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;
|
await child.status;
|
||||||
},
|
},
|
||||||
|
@ -120,8 +140,16 @@ Deno.test(
|
||||||
});
|
});
|
||||||
const child = command.spawn();
|
const child = command.spawn();
|
||||||
|
|
||||||
assertThrows(() => child.stdin, TypeError, "stdin is not piped");
|
assertThrows(
|
||||||
assertThrows(() => child.stderr, TypeError, "stderr is not piped");
|
() => 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 readable = child.stdout.pipeThrough(new TextDecoderStream());
|
||||||
const reader = readable.getReader();
|
const reader = readable.getReader();
|
||||||
|
@ -154,8 +182,16 @@ Deno.test(
|
||||||
});
|
});
|
||||||
const child = command.spawn();
|
const child = command.spawn();
|
||||||
|
|
||||||
assertThrows(() => child.stdin, TypeError, "stdin is not piped");
|
assertThrows(
|
||||||
assertThrows(() => child.stdout, TypeError, "stdout is not piped");
|
() => 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 readable = child.stderr.pipeThrough(new TextDecoderStream());
|
||||||
const reader = readable.getReader();
|
const reader = readable.getReader();
|
||||||
|
@ -955,7 +991,7 @@ Deno.test(
|
||||||
assertThrows(
|
assertThrows(
|
||||||
() => child.kill(),
|
() => child.kill(),
|
||||||
TypeError,
|
TypeError,
|
||||||
"Child process has already terminated.",
|
"Child process has already terminated",
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -120,7 +120,7 @@ Deno.test(function permissionQueryForReadReturnsSameStatusSync() {
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test(function permissionsIllegalConstructor() {
|
Deno.test(function permissionsIllegalConstructor() {
|
||||||
assertThrows(() => new Deno.Permissions(), TypeError, "Illegal constructor.");
|
assertThrows(() => new Deno.Permissions(), TypeError, "Illegal constructor");
|
||||||
assertEquals(Deno.Permissions.length, 0);
|
assertEquals(Deno.Permissions.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ Deno.test(function permissionStatusIllegalConstructor() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
() => new Deno.PermissionStatus(),
|
() => new Deno.PermissionStatus(),
|
||||||
TypeError,
|
TypeError,
|
||||||
"Illegal constructor.",
|
"Illegal constructor",
|
||||||
);
|
);
|
||||||
assertEquals(Deno.PermissionStatus.length, 0);
|
assertEquals(Deno.PermissionStatus.length, 0);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue