windmill-labs/windmill · error

File already exists: + scriptCodeFileFullPath

Error message

File already exists: + scriptCodeFileFullPath

What it means

`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.

Source

Thrown at cli/src/commands/script/script.ts:1650

  if (scriptInitialCode === undefined) {
    const validLanguages = Object.keys(scriptBootstrapCode).sort().join(", ");
    throw new Error(
      `Unknown language '${language}'. Valid languages: ${validLanguages}`
    );
  }

  const config = await readConfigFile();

  const extension = filePathExtensionFromContentType(
    resolvedLanguage,
    config.defaultTs
  );
  const scriptCodeFileFullPath = scriptPath + extension;
  const scriptMetadataFileFullPath = scriptPath + ".script.yaml";

  try {
    await stat(scriptCodeFileFullPath);
    throw new Error("File already exists: " + scriptCodeFileFullPath);
  } catch (e: any) {
    if (e.message?.startsWith("File already exists")) throw e;
  }
  try {
    await stat(scriptMetadataFileFullPath);
    throw new Error("File already exists: " + scriptMetadataFileFullPath);
  } catch (e: any) {
    if (e.message?.startsWith("File already exists")) throw e;
  }

  const scriptMetadata = defaultScriptMetadata();
  if (opts.summary !== undefined) {
    scriptMetadata.summary = opts.summary;
  }
  if (opts.description !== undefined) {
    scriptMetadata.description = opts.description;
  }

View on GitHub (pinned to e474e8803c)

Solutions

  1. Delete or rename the existing code file if it's safe to overwrite.
  2. Bootstrap into a different path/filename.
  3. Merge the starter code manually into the existing file instead of bootstrapping again.
  4. If the file is a leftover artifact, remove it and re-run bootstrap.

Example fix

// before
wmill script bootstrap f/my_script python   # my_script.py exists
// after
rm f/my_script.py
wmill script bootstrap f/my_script python
Defensive patterns

Strategy: validation

Validate before calling

import { statSync, existsSync } from 'fs';
const codeFile = path + extFor(language);
if (existsSync(codeFile)) {
  console.error(`${codeFile} exists — move/remove it or pick another path.`);
  process.exit(1);
}

Try / catch

try {
  await wmill.script.bootstrap(p, lang);
} catch (e) {
  if (String(e.message).startsWith('File already exists')) {
    console.error('Pick a new path or delete the existing file first.');
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/43a220d51e687533. Report an issue: GitHub.