{"record":{"id":"43a220d51e687533","repo":"windmill-labs/windmill","slug":"file-already-exists-scriptcodefilefullpath","errorCode":null,"errorMessage":"File already exists: + scriptCodeFileFullPath","messagePattern":"File already exists: \\+ scriptCodeFileFullPath","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/src/commands/script/script.ts","lineNumber":1650,"sourceCode":"  if (scriptInitialCode === undefined) {\n    const validLanguages = Object.keys(scriptBootstrapCode).sort().join(\", \");\n    throw new Error(\n      `Unknown language '${language}'. Valid languages: ${validLanguages}`\n    );\n  }\n\n  const config = await readConfigFile();\n\n  const extension = filePathExtensionFromContentType(\n    resolvedLanguage,\n    config.defaultTs\n  );\n  const scriptCodeFileFullPath = scriptPath + extension;\n  const scriptMetadataFileFullPath = scriptPath + \".script.yaml\";\n\n  try {\n    await stat(scriptCodeFileFullPath);\n    throw new Error(\"File already exists: \" + scriptCodeFileFullPath);\n  } catch (e: any) {\n    if (e.message?.startsWith(\"File already exists\")) throw e;\n  }\n  try {\n    await stat(scriptMetadataFileFullPath);\n    throw new Error(\"File already exists: \" + scriptMetadataFileFullPath);\n  } catch (e: any) {\n    if (e.message?.startsWith(\"File already exists\")) throw e;\n  }\n\n  const scriptMetadata = defaultScriptMetadata();\n  if (opts.summary !== undefined) {\n    scriptMetadata.summary = opts.summary;\n  }\n  if (opts.description !== undefined) {\n    scriptMetadata.description = opts.description;\n  }\n","sourceCodeStart":1632,"sourceCodeEnd":1668,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/cli/src/commands/script/script.ts#L1632-L1668","documentation":"`wmill script bootstrap` refuses to overwrite existing files. Before writing the script code file (`<path><extension>`), it calls `stat` on the target; if the file exists, it throws 'File already exists'. The catch block distinguishes this deliberate error from the ENOENT thrown by `stat` itself.","triggerScenarios":"Running `wmill script bootstrap f/my_script <lang>` twice in the same directory, or where a file named e.g. `my_script.ts` already exists from manual creation or a previous scaffold with a different language that maps to the same extension.","commonSituations":"Re-running a bootstrap command after an interrupted/partial first run; scaffolding a second script into a folder where the filename collides; scripts generated by a prior tool (cookiecutter, IDE) occupying the name.","solutions":["Delete or rename the existing code file if it's safe to overwrite.","Bootstrap into a different path/filename.","Merge the starter code manually into the existing file instead of bootstrapping again.","If the file is a leftover artifact, remove it and re-run bootstrap."],"exampleFix":"// before\nwmill script bootstrap f/my_script python   # my_script.py exists\n// after\nrm f/my_script.py\nwmill script bootstrap f/my_script python","handlingStrategy":"validation","validationCode":"import { statSync, existsSync } from 'fs';\nconst codeFile = path + extFor(language);\nif (existsSync(codeFile)) {\n  console.error(`${codeFile} exists — move/remove it or pick another path.`);\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await wmill.script.bootstrap(p, lang);\n} catch (e) {\n  if (String(e.message).startsWith('File already exists')) {\n    console.error('Pick a new path or delete the existing file first.');\n  }\n  throw e;\n}","preventionTips":["Run bootstrap only once per path; use git to recover, not re-bootstrap.","Check the target directory with `ls` before scaffolding.","Use unique script paths per feature to avoid collisions."],"tags":["cli","filesystem","file-conflict","bootstrap"],"backgroundTag":"file-already-exists","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}