denoland/deno · error · Error
'options' requires at least one option to be true
Error message
'options' requires at least one option to be true
What it means
checkOpenOptions validates the options bag passed to Deno.open/openSync before anything is opened. At least one flag (read, write, append, truncate, create, createNew) must be true, otherwise the operation would have no effect at all, so a plain Error is thrown. An empty object {} also fails this check since zero values are true.
Source
Thrown at ext/fs/30_fs.js:801
}
async unlock() {
await op_fs_funlock_async(this.#rid);
}
[SymbolDispose]() {
core.tryClose(this.#rid);
}
}
function checkOpenOptions(options) {
if (
ArrayPrototypeFilter(
ObjectValues(options),
(val) => val === true,
).length === 0
) {
throw new Error(
"'options' requires at least one option to be true",
);
}
if (options.truncate && !options.write) {
throw new Error(
"'truncate' option requires 'write' to be true",
);
}
const createOrCreateNewWithoutWriteOrAppend =
(options.create || options.createNew) &&
!(options.write || options.append);
if (createOrCreateNewWithoutWriteOrAppend) {
throw new Error(
"'create' or 'createNew' options require 'write' or 'append' to be true",
);View on GitHub (pinned to 89f33cbef2)
Solutions
- Pass at least one true flag, e.g. { read: true }
- Map Node flags: 'r' -> { read: true }, 'w' -> { write: true, create: true, truncate: true }, 'a' -> { append: true, create: true }
- Validate programmatically-built options before calling open
Example fix
// before
await Deno.open("/tmp/x", {}); // Error
// after
await Deno.open("/tmp/x", { read: true }); Defensive patterns
Strategy: validation
Validate before calling
function hasAnyTrueFlag(options) {
return Object.values(options).some((v) => v === true);
}
if (!hasAnyTrueFlag(options)) {
options = { ...options, read: true }; // or reject with a clear message
}
await Deno.open(path, options); Type guard
function isOpenOptionsValid(options: Record<string, unknown>): boolean {
return Object.values(options).some((v) => v === true);
} Try / catch
try {
file = await Deno.open(path, options);
} catch (err) {
if (err instanceof Error && err.message === "'options' requires at least one option to be true") {
file = await Deno.open(path, { ...options, read: true });
} else throw err;
} Prevention
- Never pass an empty options object to open/openSync
- Map Node flag strings once: r -> read, w -> write+create+truncate, a -> append+create
- Beware typos like read: flase that silently become undefined
When it happens
Trigger: Deno.open(path, {}) or Deno.openSync(path, { read: false, write: false }) — an options object in which no value equals true.
Common situations: Options built programmatically where all flags end up false depending on input; porting Node's fs.open flag strings and passing an empty object for 'r'; a falsy flag typo like read: flase (misspelling) silently evaluating to undefined.
Related errors
- 'truncate' option requires 'write' to be true
- 'create' or 'createNew' options require 'write' or 'append'
- A file exists at the destination: ${destStr}
- ERR_MISSING_ARGS
- No callback function supplied
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/8b7fe20b8064069c.
Report an issue: GitHub.