{"record":{"id":"d12d186a09ae0bdf","repo":"denoland/deno","slug":"on-windows-an-options-argument-is-required-if-th","errorCode":null,"errorMessage":"On Windows an `options` argument is required if the target does not exist","messagePattern":"On Windows an `options` argument is required if the target does not exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ext/fs/std_fs.rs","lineNumber":1240,"sourceCode":"  let file_type = match file_type {\n    Some(file_type) => file_type,\n    None => {\n      let old_meta = fs::metadata(oldpath);\n      match old_meta {\n        Ok(metadata) => {\n          if metadata.is_file() {\n            FsFileType::File\n          } else if metadata.is_dir() {\n            FsFileType::Directory\n          } else {\n            return Err(FsError::Io(io::Error::new(\n              io::ErrorKind::InvalidInput,\n              \"On Windows the target must be a file or directory\",\n            )));\n          }\n        }\n        Err(err) if err.kind() == io::ErrorKind::NotFound => {\n          return Err(FsError::Io(io::Error::new(\n            io::ErrorKind::InvalidInput,\n            \"On Windows an `options` argument is required if the target does not exist\",\n          )));\n        }\n        Err(err) => return Err(err.into()),\n      }\n    }\n  };\n\n  match file_type {\n    FsFileType::File => {\n      std::os::windows::fs::symlink_file(oldpath, newpath)?;\n    }\n    FsFileType::Directory => {\n      std::os::windows::fs::symlink_dir(oldpath, newpath)?;\n    }\n    FsFileType::Junction => {\n      junction::create(oldpath, newpath)?;","sourceCodeStart":1222,"sourceCodeEnd":1258,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/fs/std_fs.rs#L1222-L1258","documentation":"On Windows, when Deno.symlink()/symlinkSync() is called without options, Deno stats oldpath to infer the link type; if fs::metadata returns NotFound (the target does not exist), inference is impossible and the call fails with io::ErrorKind::InvalidInput 'On Windows an `options` argument is required if the target does not exist' (ext/fs/std_fs.rs:1240). Unix allows dangling symlinks, so this is Windows-specific.","triggerScenarios":"Deno.symlinkSync('./config.toml', 'link.toml') before ./config.toml exists; installers pre-creating links to paths a later setup step will materialize; any code relying on dangling symlinks on Windows.","commonSituations":"Cross-platform scripts developed on macOS/Linux (dangling links fine) breaking on Windows; dotfile managers creating links before stowing files.","solutions":["Create the target first, then the symlink","Always pass { type: 'file' } or { type: 'dir' } on Windows when the target may be absent","Gate dangling-link behavior on Deno.build.os !== 'windows'"],"exampleFix":"// before\nDeno.symlinkSync('./config.toml', 'link.toml'); // config.toml missing, Windows\n\n// after\nDeno.symlinkSync('./config.toml', 'link.toml', { type: 'file' });","handlingStrategy":"validation","validationCode":"function ensureSymlinkable(target: string, link: string): void {\n  const onWindows = Deno.build.os === 'windows';\n  let type: 'file' | 'dir' | undefined;\n  if (onWindows) {\n    try {\n      type = Deno.statSync(target).isDirectory ? 'dir' : 'file';\n    } catch {\n      type = undefined; // target missing: caller must decide the link type\n    }\n  }\n  if (onWindows && !type) {\n    throw new Error(\n      `Windows cannot infer link type; pass { type } or create the target first: ${target}`,\n    );\n  }\n  Deno.symlinkSync(target, link, type ? { type } : undefined);\n}","typeGuard":"async function targetExists(target: string): Promise<boolean> {\n  try {\n    await Deno.stat(target);\n    return true;\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":null,"preventionTips":["Create the target file/directory before symlinking it on Windows","Pass { type: 'file' } or { type: 'dir' } explicitly in cross-platform code","Do not port Unix dangling-symlink patterns to Windows"],"tags":["filesystem","symlink","windows","not-found","deno"],"backgroundTag":"windows-symlink-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}