{"record":{"id":"745f9e7c17dad73e","repo":"denoland/deno","slug":"create-or-createnew-options-require-write-or","errorCode":null,"errorMessage":"'create' or 'createNew' options require 'write' or 'append' to be true","messagePattern":"'create' or 'createNew' options require 'write' or 'append' to be true","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ext/fs/30_fs.js","lineNumber":817,"sourceCode":"    ).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    );\n  }\n}\n\nfunction readFileSync(path) {\n  return op_fs_read_file_sync(pathFromURL(path));\n}\n\nasync function readFile(path, options) {\n  let cancelRid;\n  let abortHandler;\n  if (options?.signal) {\n    options.signal.throwIfAborted();\n    cancelRid = createCancelHandle();\n    abortHandler = () => core.tryClose(cancelRid);\n    options.signal[abortSignal.add](abortHandler);\n  }","sourceCodeStart":799,"sourceCodeEnd":835,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/fs/30_fs.js#L799-L835","documentation":"create and createNew make Deno.open create the file, which only makes sense on a writable or appendable handle. Opening with create flags but no write/append would create a file you could not write to, so Deno rejects the combination before touching the filesystem.","triggerScenarios":"Deno.open(path, { create: true }); Deno.open(path, { createNew: true, read: true }) with no write/append; 'ensure the file exists' logic implemented as open-with-create.","commonSituations":"Touch-like existence checks; porting Node fs.open mappings; copy-pasted option objects where the write line was dropped.","solutions":["Add write: true (or append: true) whenever create/createNew is used","For create-and-write semantics use the shorthand Deno.create(path) (read+write+create+truncate)","For touch-like behavior, Deno.createSync(path) then immediately close"],"exampleFix":"// before\nconst f = await Deno.open(path, { create: true });\n\n// after\nconst f = await Deno.open(path, { read: true, write: true, create: true });","handlingStrategy":"validation","validationCode":"function normalizeOpenOptions(o) {\n  if ((o.create || o.createNew) && !(o.write || o.append)) {\n    o = { ...o, write: true };\n  }\n  return o;\n}\n\nconst f = await Deno.open(path, normalizeOpenOptions(opts));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat create/createNew as write-intent flags and always add write or append","Prefer the Deno.create() shorthand for create-and-write","Do not use open-with-create as an 'ensure exists' probe"],"tags":["fs","open","options","create"],"backgroundTag":"invalid-option-combination","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}