{"record":{"id":"849dcdcfadd78589","repo":"windmill-labs/windmill","slug":"file-already-exists-filepath-849dcd","errorCode":null,"errorMessage":"File already exists: ${filePath}","messagePattern":"File already exists: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/trigger/trigger.ts","lineNumber":445,"sourceCode":"    enabled: false,\n  },\n};\n\nasync function newTrigger(opts: GlobalOptions & { kind: string }, path: string) {\n  if (!validatePath(path)) {\n    return;\n  }\n  if (!opts.kind) {\n    throw new Error(\"--kind is required. Valid kinds: \" + TRIGGER_TYPES.join(\", \"));\n  }\n  if (!checkIfValidTrigger(opts.kind)) {\n    throw new Error(\"Invalid trigger kind: \" + opts.kind + \". Valid kinds: \" + TRIGGER_TYPES.join(\", \"));\n  }\n  const kind: TriggerType = opts.kind;\n  const filePath = `${path}.${kind}_trigger.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  }\n  const template = triggerTemplates[kind];\n  await mkdir(dirname(filePath), { recursive: true });\n  await writeFile(filePath, yamlStringify(template), {\n    flag: \"wx\",\n    encoding: \"utf-8\",\n  });\n  log.info(colors.green(`Created ${filePath}`));\n}\n\nconst TRIGGER_SKIP_FIELDS = new Set([\"workspace_id\", \"extra_perms\", \"edited_by\", \"edited_at\"]);\n\nfunction printTriggerDetails(trigger: any, kind: string) {\n  console.log(colors.bold(\"Path:\") + \" \" + trigger.path);\n  console.log(colors.bold(\"Kind:\") + \" \" + kind);\n  console.log(colors.bold(\"Enabled:\") + \" \" + (trigger.enabled ?? trigger.mode ?? \"-\"));","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/cli/src/commands/trigger/trigger.ts#L427-L463","documentation":"`wmill trigger new` writes a YAML template for the new trigger and refuses to overwrite an existing file: it stats the target path `{path}.{kind}_trigger.yaml` and throws this error if it exists. The catch block explicitly re-throws errors starting with \"File already exists\" so stat failures (ENOENT) fall through and creation proceeds.","triggerScenarios":"Running `wmill trigger new u/admin/myscript --kind schedule` twice, or when a file u/admin/myscript.schedule_trigger.yaml already exists from a previous creation or sync pull.","commonSituations":"Re-running an init script that isn't idempotent; onboarding docs executed twice; collisions when several triggers share the same base path and kind naming.","solutions":["Choose a different path for the new trigger","Delete or rename the existing YAML file if it is obsolete, then re-run","Edit the existing file instead of creating a new trigger","Use the existing trigger remotely via `wmill trigger get` to verify it before recreating"],"exampleFix":"// before\nwmill trigger new u/admin/myscript --kind schedule\n# Error: File already exists: u/admin/myscript.schedule_trigger.yaml\n// after\nwmill trigger new u/admin/myscript_v2 --kind schedule","handlingStrategy":"try-catch","validationCode":"import { stat } from \"fs/promises\";\nconst target = `${path}.${kind}_trigger.yaml`;\nconst exists = await stat(target).then(() => true, () => false);\nif (exists) console.warn(\"trigger file already present, pick another path or edit it\");","typeGuard":null,"tryCatchPattern":"try {\n  await wmill.trigger.new(opts, p);\n} catch (e) {\n  if (String(e.message).startsWith(\"File already exists\")) {\n    console.warn(e.message, \"— edit existing file or choose a new path\");\n  }\n}","preventionTips":["Make init scripts idempotent (check existence before new)","Use unique base paths per trigger","Keep trigger YAML files in git to see what already exists"],"tags":["cli","trigger","file-conflict","idempotency"],"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"}