Skip to content

Commit

Permalink
refactor(ext/fs): align error messages (#25414)
Browse files Browse the repository at this point in the history
Aligns the error messages in the ext/fs folder to be in-line with the
Deno style guide.
  • Loading branch information
irbull authored Nov 28, 2024
1 parent 3553aa9 commit 8626ec7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions ext/fs/30_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class FsFile {
this.#rid = rid;
if (!symbol || symbol !== SymbolFor("Deno.internal.FsFile")) {
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",
);
}
}
Expand Down Expand Up @@ -713,11 +713,15 @@ function checkOpenOptions(options) {
(val) => val === true,
).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) {
throw new Error("'truncate' option requires 'write' option");
throw new Error(
"'truncate' option requires 'write' to be true",
);
}

const createOrCreateNewWithoutWriteOrAppend =
Expand All @@ -726,7 +730,7 @@ function checkOpenOptions(options) {

if (createOrCreateNewWithoutWriteOrAppend) {
throw new Error(
"'create' or 'createNew' options require 'write' or 'append' option",
"'create' or 'createNew' options require 'write' or 'append' to be true",
);
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/files_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,31 +137,31 @@ Deno.test(async function openOptions() {
await Deno.open(filename, { write: false });
},
Error,
"OpenOptions requires at least one option to be true",
"'options' requires at least one option to be true",
);

await assertRejects(
async () => {
await Deno.open(filename, { truncate: true, write: false });
},
Error,
"'truncate' option requires 'write' option",
"'truncate' option requires 'write' to be true",
);

await assertRejects(
async () => {
await Deno.open(filename, { create: true, write: false });
},
Error,
"'create' or 'createNew' options require 'write' or 'append' option",
"'create' or 'createNew' options require 'write' or 'append' to be true",
);

await assertRejects(
async () => {
await Deno.open(filename, { createNew: true, append: false });
},
Error,
"'create' or 'createNew' options require 'write' or 'append' option",
"'create' or 'createNew' options require 'write' or 'append' to be true",
);
});

Expand Down

0 comments on commit 8626ec7

Please sign in to comment.