windmill-labs/windmill · error
File already exists: + filePath
Error message
File already exists: + filePath
What it means
Thrown by `wmill resource new` when the target file already exists on disk. The command derives filePath as '<path>.resource.yaml', stats it, and if stat succeeds the file is already there, so it refuses to overwrite an existing resource file rather than clobbering local work.
Source
Thrown at cli/src/commands/resource/resource.ts:231
console.log(JSON.stringify(total));
} else {
new Table()
.header(["Path", "Resource Type"])
.padding(2)
.border(true)
.body(total.map((x) => [x.path, x.resource_type]))
.render();
}
}
async function newResource(opts: GlobalOptions, path: string) {
if (!validatePath(path)) {
return;
}
const filePath = path + ".resource.yaml";
try {
await stat(filePath);
throw new Error("File already exists: " + filePath);
} catch (e: any) {
if (e.message?.startsWith("File already exists")) throw e;
// file doesn't exist, proceed
}
const template: ResourceFile = {
value: {},
resource_type: "",
description: "",
};
await mkdir(nodePath.dirname(filePath), { recursive: true });
await writeFile(filePath, yamlStringify(template as Record<string, any>), {
flag: "wx",
encoding: "utf-8",
});
log.info(colors.green(`Created ${filePath}`));
}
async function get(opts: GlobalOptions & { json?: boolean }, path: string) {View on GitHub (pinned to e474e8803c)
Solutions
- Edit the existing <path>.resource.yaml directly instead of re-running `resource new`
- Delete or rename (e.g. `git rm`/`git mv`) the existing file if you truly want to regenerate it from scratch
- Use `wmill resource push` to update an existing resource remotely rather than scaffolding a new local file
Example fix
// before $ wmill resource new u/admin/myres Error: File already exists: u/admin/myres.resource.yaml // after: edit the existing file, or $ git mv u/admin/myres.resource.yaml u/admin/myres.resource.yaml.bak && wmill resource new u/admin/myres
Defensive patterns
Strategy: try-catch
Validate before calling
import { statSync } from 'fs';
const filePath = path + '.resource.yaml';
try {
statSync(filePath);
throw new Error(`refusing: ${filePath} already exists; edit it or pick another path`);
} catch (e: any) {
if (String(e.message).startsWith('refusing:')) throw e; // exists
// otherwise ENOENT -> safe to create
} Try / catch
try {
await wmill.resource.new(path, ...);
} catch (e) {
if ((e as Error).message.startsWith('File already exists')) {
// open and edit the existing file, or push it, or delete it deliberately
} else throw e;
} Prevention
- Make scaffolding scripts idempotent: check existence (or use `if [ ! -f ]`) before calling `resource new`
- Remember the command appends `.resource.yaml` — pick paths that cannot collide
- Prefer editing/pushing existing files over re-running `new` for changes
- Commit generated resource files so teammates see existing names before scaffolding
When it happens
Trigger: Running `wmill resource new <path>` where `<path>.resource.yaml` already exists in the working directory; accidentally running the scaffolding command twice; path normalization differences (e.g. trailing slash, './' prefix) that still resolve to the same existing file.
Common situations: Re-running an init/setup script that creates resource files; intending to update an existing resource but using `new` instead of editing the YAML or using `push`; multiple team members scaffolding into the same shared directory; forgetting the command appends `.resource.yaml` and picking a path that collides.
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
- File already exists: + filePath
- file path must refer to a file.
- file path must refer to a file.
- File not found: ${filePath}
- Workspace folder not found, are you in the right directory?
AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03).
Data as JSON: /api/errors/bde915ad090a0391.
Report an issue: GitHub.