{"record":{"id":"02cab8e53e287e4e","repo":"windmill-labs/windmill","slug":"file-already-exists-filepath-02cab8","errorCode":null,"errorMessage":"File already exists: + filePath","messagePattern":"File already exists: \\+ filePath","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/src/commands/schedule/schedule.ts","lineNumber":63,"sourceCode":"    console.log(JSON.stringify(schedules));\n  } else {\n    new Table()\n      .header([\"Path\", \"Schedule\"])\n      .padding(2)\n      .border(true)\n      .body(schedules.map((x) => [x.path, x.schedule]))\n      .render();\n  }\n}\n\nasync function newSchedule(opts: GlobalOptions, path: string) {\n  if (!validatePath(path)) {\n    return;\n  }\n  const filePath = path + \".schedule.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: ScheduleFile = {\n    schedule: \"0 0 */6 * * *\",\n    on_failure: \"\",\n    script_path: \"\",\n    args: {},\n    timezone: \"Etc/UTC\",\n    is_flow: false,\n    enabled: false,\n  };\n  await mkdir(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}`));","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/cli/src/commands/schedule/schedule.ts#L45-L81","documentation":"Thrown by `wmill schedule new` when the target schedule file already exists on disk. The command builds filePath as '<path>.schedule.yaml' and stats it; a successful stat means the file exists, so the CLI throws rather than overwriting an existing schedule definition.","triggerScenarios":"Running `wmill schedule new <path>` where `<path>.schedule.yaml` already exists; re-running a scaffolding script; choosing a path that differs textually ('./x', 'a/../x') but resolves to an existing file.","commonSituations":"Re-running project bootstrap scripts; wanting to change a schedule but using `new` instead of editing the existing YAML or pushing; cron-pattern iteration where you recreate schedules repeatedly; forgetting the `.schedule.yaml` suffix is appended so the intended unique path collides.","solutions":["Edit the existing <path>.schedule.yaml (schedule, cron, is_enabled, etc.) instead of re-running `schedule new`","Remove or rename the existing file (`git rm` / `git mv`) if regeneration is intended","Use `wmill schedule push` on the edited file to update the remote schedule"],"exampleFix":"// before\n$ wmill schedule new u/admin/nightly\nError: File already exists: u/admin/nightly.schedule.yaml\n// after: edit u/admin/nightly.schedule.yaml, then\n$ wmill schedule push u/admin/nightly.schedule.yaml","handlingStrategy":"try-catch","validationCode":"import { statSync } from 'fs';\n\nconst filePath = path + '.schedule.yaml';\nlet exists = false;\ntry { statSync(filePath); exists = true; } catch { /* ENOENT: safe */ }\nif (exists) throw new Error(`refusing: ${filePath} already exists`);","typeGuard":null,"tryCatchPattern":"try {\n  await wmill.schedule.new(path, ...);\n} catch (e) {\n  if ((e as Error).message.startsWith('File already exists')) {\n    // edit the existing .schedule.yaml (e.g. change cron) and `schedule push` instead\n  } else throw e;\n}","preventionTips":["Edit the existing `.schedule.yaml` and push, rather than re-running `schedule new` for cron changes","Make bootstrap scripts idempotent by checking for `<path>.schedule.yaml` first","Account for the appended `.schedule.yaml` suffix when choosing unique paths","Keep schedule files in git so re-creation attempts are visible in review"],"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"}