{"record":{"id":"8b7fe20b8064069c","repo":"denoland/deno","slug":"options-requires-at-least-one-option-to-be-true","errorCode":null,"errorMessage":"'options' requires at least one option to be true","messagePattern":"'options' requires at least one option to be true","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ext/fs/30_fs.js","lineNumber":801,"sourceCode":"  }\n\n  async unlock() {\n    await op_fs_funlock_async(this.#rid);\n  }\n\n  [SymbolDispose]() {\n    core.tryClose(this.#rid);\n  }\n}\n\nfunction checkOpenOptions(options) {\n  if (\n    ArrayPrototypeFilter(\n      ObjectValues(options),\n      (val) => val === true,\n    ).length === 0\n  ) {\n    throw new Error(\n      \"'options' requires at least one option to be true\",\n    );\n  }\n\n  if (options.truncate && !options.write) {\n    throw new Error(\n      \"'truncate' option requires 'write' to be true\",\n    );\n  }\n\n  const createOrCreateNewWithoutWriteOrAppend =\n    (options.create || options.createNew) &&\n    !(options.write || options.append);\n\n  if (createOrCreateNewWithoutWriteOrAppend) {\n    throw new Error(\n      \"'create' or 'createNew' options require 'write' or 'append' to be true\",\n    );","sourceCodeStart":783,"sourceCodeEnd":819,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/fs/30_fs.js#L783-L819","documentation":"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.","triggerScenarios":"Deno.open(path, {}) or Deno.openSync(path, { read: false, write: false }) — an options object in which no value equals true.","commonSituations":"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.","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"],"exampleFix":"// before\nawait Deno.open(\"/tmp/x\", {}); // Error\n\n// after\nawait Deno.open(\"/tmp/x\", { read: true });","handlingStrategy":"validation","validationCode":"function hasAnyTrueFlag(options) {\n  return Object.values(options).some((v) => v === true);\n}\nif (!hasAnyTrueFlag(options)) {\n  options = { ...options, read: true }; // or reject with a clear message\n}\nawait Deno.open(path, options);","typeGuard":"function isOpenOptionsValid(options: Record<string, unknown>): boolean {\n  return Object.values(options).some((v) => v === true);\n}","tryCatchPattern":"try {\n  file = await Deno.open(path, options);\n} catch (err) {\n  if (err instanceof Error && err.message === \"'options' requires at least one option to be true\") {\n    file = await Deno.open(path, { ...options, read: true });\n  } else throw err;\n}","preventionTips":["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"],"tags":["fs","open","options","validation"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}