Skip to content

Commit

Permalink
refactor(ext/fs): align error messages
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.

denoland#25269
  • Loading branch information
irbull committed Sep 4, 2024
1 parent b72d1a7 commit 373b21d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions ext/fs/30_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ class FsFile {
);
if (internals.future) {
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 @@ -776,11 +776,15 @@ function checkOpenOptions(options) {
(val) => val === true,
).length === 0
) {
throw new Error("OpenOptions requires at least one option to be true");
throw new Error(
"Cannot open file: `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(
"Cannot open file: 'truncate' option requires 'write' to be true",
);
}

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

if (createOrCreateNewWithoutWriteOrAppend) {
throw new Error(
"'create' or 'createNew' options require 'write' or 'append' option",
"Cannot open file: 'create' or 'createNew' options require 'write' or 'append' to be true",
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/future/runtime_api/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ try {
if (
error instanceof TypeError &&
error.message ===
"`Deno.FsFile` cannot be constructed, use `Deno.open()` or `Deno.openSync()` instead."
"`Deno.FsFile` cannot be constructed, use `Deno.open()` or `Deno.openSync()` instead"
) {
console.log("Deno.FsFile constructor is illegal");
}
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 @@ -139,31 +139,31 @@ Deno.test(async function openOptions() {
await Deno.open(filename, { write: false });
},
Error,
"OpenOptions requires at least one option to be true",
"Cannot open file: `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",
"Cannot open file: '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",
"Cannot open file: '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",
"Cannot open file: 'create' or 'createNew' options require 'write' or 'append' to be true",
);
});

Expand Down

0 comments on commit 373b21d

Please sign in to comment.