{"record":{"id":"bde915ad090a0391","repo":"windmill-labs/windmill","slug":"file-already-exists-filepath-bde915","errorCode":null,"errorMessage":"File already exists: + filePath","messagePattern":"File already exists: \\+ filePath","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/src/commands/resource/resource.ts","lineNumber":231,"sourceCode":"    console.log(JSON.stringify(total));\n  } else {\n    new Table()\n      .header([\"Path\", \"Resource Type\"])\n      .padding(2)\n      .border(true)\n      .body(total.map((x) => [x.path, x.resource_type]))\n      .render();\n  }\n}\n\nasync function newResource(opts: GlobalOptions, path: string) {\n  if (!validatePath(path)) {\n    return;\n  }\n  const filePath = path + \".resource.yaml\";\n  try {\n    await stat(filePath);\n    throw new Error(\"File already exists: \" + filePath);\n  } catch (e: any) {\n    if (e.message?.startsWith(\"File already exists\")) throw e;\n    // file doesn't exist, proceed\n  }\n  const template: ResourceFile = {\n    value: {},\n    resource_type: \"\",\n    description: \"\",\n  };\n  await mkdir(nodePath.dirname(filePath), { recursive: true });\n  await writeFile(filePath, yamlStringify(template as Record<string, any>), {\n    flag: \"wx\",\n    encoding: \"utf-8\",\n  });\n  log.info(colors.green(`Created ${filePath}`));\n}\n\nasync function get(opts: GlobalOptions & { json?: boolean }, path: string) {","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/cli/src/commands/resource/resource.ts#L213-L249","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n$ wmill resource new u/admin/myres\nError: File already exists: u/admin/myres.resource.yaml\n// after: edit the existing file, or\n$ git mv u/admin/myres.resource.yaml u/admin/myres.resource.yaml.bak && wmill resource new u/admin/myres","handlingStrategy":"try-catch","validationCode":"import { statSync } from 'fs';\n\nconst filePath = path + '.resource.yaml';\ntry {\n  statSync(filePath);\n  throw new Error(`refusing: ${filePath} already exists; edit it or pick another path`);\n} catch (e: any) {\n  if (String(e.message).startsWith('refusing:')) throw e; // exists\n  // otherwise ENOENT -> safe to create\n}","typeGuard":null,"tryCatchPattern":"try {\n  await wmill.resource.new(path, ...);\n} catch (e) {\n  if ((e as Error).message.startsWith('File already exists')) {\n    // open and edit the existing file, or push it, or delete it deliberately\n  } else throw e;\n}","preventionTips":["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"],"tags":["cli","windmill","filesystem","duplicate-file"],"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"}