{"record":{"id":"95c66d0b189b3df5","repo":"phacility/phabricator","slug":"output-path-already-exists-use-overwrite-to-o","errorCode":null,"errorMessage":"Output path already exists. Use \"--overwrite\" to overwrite it.","messagePattern":"Output path already exists\\. Use \"--overwrite\" to overwrite it\\.","errorType":"console","errorClass":"PhutilArgumentUsageException","httpStatus":null,"severity":"error","filePath":"src/applications/transactions/bulk/management/PhabricatorBulkManagementExportWorkflow.php","lineNumber":101,"sourceCode":"          'Use \"--output <path>\" to specify an output file, or \"--output -\" '.\n          'to print to stdout.'));\n    }\n\n    if ($output_path === '-') {\n      $is_stdout = true;\n    } else {\n      $is_stdout = false;\n    }\n\n    if ($is_stdout && $is_overwrite) {\n      throw new PhutilArgumentUsageException(\n        pht(\n          'Flag \"--overwrite\" has no effect when outputting to stdout.'));\n    }\n\n    if (!$is_overwrite) {\n      if (!$is_stdout && Filesystem::pathExists($output_path)) {\n        throw new PhutilArgumentUsageException(\n          pht(\n            'Output path already exists. Use \"--overwrite\" to overwrite '.\n            'it.'));\n      }\n    }\n\n    // If we have more than one query, execute the queries to figure out which\n    // results they hit, then build a synthetic query for all those results\n    // using the IDs.\n    if (count($queries) > 1) {\n      $saved_query = $this->newUnionQuery($engine, $queries);\n    } else {\n      $saved_query = head($queries);\n    }\n\n    $export_engine = id(new PhabricatorExportEngine())\n      ->setViewer($viewer)\n      ->setTitle(pht('Export'))","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/transactions/bulk/management/PhabricatorBulkManagementExportWorkflow.php#L83-L119","documentation":"The export workflow will not clobber an existing file unless told to. When the destination path exists (Filesystem::pathExists), --output is not stdout, and --overwrite was not passed, this usage exception is thrown. It protects existing data from being replaced by a re-run.","triggerScenarios":"Running an export to a path that already exists from a previous run, without --overwrite. Also triggered when the path exists as a directory, since pathExists matches any filesystem entry.","commonSituations":"Repeated cron exports writing to a fixed filename; an earlier failed run left a partial file; shared mounts (NFS, docker volumes) where another process created the file.","solutions":["Add --overwrite to the command if replacing the file is intended.","Export to a fresh path, e.g. one containing a timestamp: --output tasks-$(date +%F).csv.","Remove or move the existing file before the export runs."],"exampleFix":"# before\nbin/bulk export --query all --output /tmp/tasks.csv\n# after (if replacing the file is intended)\nbin/bulk export --query all --output /tmp/tasks.csv --overwrite","handlingStrategy":"validation","validationCode":"if [[ -e \"$DEST\" && \"$ALLOW_OVERWRITE\" != 1 ]]; then\n  echo \"output already exists: $DEST\" >&2; exit 2\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use unique, timestamped output filenames in scheduled exports.","Decide explicitly per script whether overwrite is allowed.","Add a pre-flight test -e check so failures happen before the query runs."],"tags":["phabricator","cli","export","filesystem"],"backgroundTag":"file-already-exists","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}