1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-06 22:35:51 -05:00

refactor(ext/fs): align error messages (#25414)

Aligns the error messages in the ext/fs folder to be in-line with the
Deno style guide.
This commit is contained in:
Ian Bull 2024-11-28 10:47:07 -08:00 committed by GitHub
parent 3553aa9132
commit 8626ec7c25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 8 deletions

View file

@ -578,7 +578,7 @@ class FsFile {
this.#rid = rid; this.#rid = rid;
if (!symbol || symbol !== SymbolFor("Deno.internal.FsFile")) { if (!symbol || symbol !== SymbolFor("Deno.internal.FsFile")) {
throw new TypeError( throw new TypeError(
"`Deno.FsFile` cannot be constructed, use `Deno.open()` or `Deno.openSync()` instead.", "'Deno.FsFile' cannot be constructed, use 'Deno.open()' or 'Deno.openSync()' instead",
); );
} }
} }
@ -713,11 +713,15 @@ function checkOpenOptions(options) {
(val) => val === true, (val) => val === true,
).length === 0 ).length === 0
) { ) {
throw new Error("OpenOptions requires at least one option to be true"); throw new Error(
"'options' requires at least one option to be true",
);
} }
if (options.truncate && !options.write) { if (options.truncate && !options.write) {
throw new Error("'truncate' option requires 'write' option"); throw new Error(
"'truncate' option requires 'write' to be true",
);
} }
const createOrCreateNewWithoutWriteOrAppend = const createOrCreateNewWithoutWriteOrAppend =
@ -726,7 +730,7 @@ function checkOpenOptions(options) {
if (createOrCreateNewWithoutWriteOrAppend) { if (createOrCreateNewWithoutWriteOrAppend) {
throw new Error( throw new Error(
"'create' or 'createNew' options require 'write' or 'append' option", "'create' or 'createNew' options require 'write' or 'append' to be true",
); );
} }
} }

View file

@ -137,7 +137,7 @@ Deno.test(async function openOptions() {
await Deno.open(filename, { write: false }); await Deno.open(filename, { write: false });
}, },
Error, Error,
"OpenOptions requires at least one option to be true", "'options' requires at least one option to be true",
); );
await assertRejects( await assertRejects(
@ -145,7 +145,7 @@ Deno.test(async function openOptions() {
await Deno.open(filename, { truncate: true, write: false }); await Deno.open(filename, { truncate: true, write: false });
}, },
Error, Error,
"'truncate' option requires 'write' option", "'truncate' option requires 'write' to be true",
); );
await assertRejects( await assertRejects(
@ -153,7 +153,7 @@ Deno.test(async function openOptions() {
await Deno.open(filename, { create: true, write: false }); await Deno.open(filename, { create: true, write: false });
}, },
Error, Error,
"'create' or 'createNew' options require 'write' or 'append' option", "'create' or 'createNew' options require 'write' or 'append' to be true",
); );
await assertRejects( await assertRejects(
@ -161,7 +161,7 @@ Deno.test(async function openOptions() {
await Deno.open(filename, { createNew: true, append: false }); await Deno.open(filename, { createNew: true, append: false });
}, },
Error, Error,
"'create' or 'createNew' options require 'write' or 'append' option", "'create' or 'createNew' options require 'write' or 'append' to be true",
); );
}); });