diff --git a/ext/fs/30_fs.js b/ext/fs/30_fs.js index 87607ca28c4d7b..e6a0fa0fc0a2c2 100644 --- a/ext/fs/30_fs.js +++ b/ext/fs/30_fs.js @@ -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", ); } } @@ -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 = @@ -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", ); } } diff --git a/tests/specs/future/runtime_api/main.js b/tests/specs/future/runtime_api/main.js index 4e22716f0234e0..c1759f104df0e2 100644 --- a/tests/specs/future/runtime_api/main.js +++ b/tests/specs/future/runtime_api/main.js @@ -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"); } diff --git a/tests/unit/files_test.ts b/tests/unit/files_test.ts index c9c3c011003b55..7e7e9d7f1d21d2 100644 --- a/tests/unit/files_test.ts +++ b/tests/unit/files_test.ts @@ -139,7 +139,7 @@ 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( @@ -147,7 +147,7 @@ Deno.test(async function openOptions() { 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( @@ -155,7 +155,7 @@ Deno.test(async function openOptions() { 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( @@ -163,7 +163,7 @@ Deno.test(async function openOptions() { 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", ); });