Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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