{"record":{"id":"fdd3e3d134c7705e","repo":"phacility/phabricator","slug":"flag-overwrite-has-no-effect-when-outputting-t","errorCode":null,"errorMessage":"Flag \"--overwrite\" has no effect when outputting to stdout.","messagePattern":"Flag \"--overwrite\" has no effect when outputting to stdout\\.","errorType":"console","errorClass":"PhutilArgumentUsageException","httpStatus":null,"severity":"error","filePath":"src/applications/transactions/bulk/management/PhabricatorBulkManagementExportWorkflow.php","lineNumber":94,"sourceCode":"\n    $is_overwrite = $args->getArg('overwrite');\n    $output_path = $args->getArg('output');\n\n    if (!strlen($output_path)) {\n      throw new PhutilArgumentUsageException(\n        pht(\n          '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);","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/transactions/bulk/management/PhabricatorBulkManagementExportWorkflow.php#L76-L112","documentation":"The export workflow rejects combining --overwrite with '--output -'. Overwrite semantics only apply to files; stdout cannot be overwritten, so the flag is meaningless there. Phabricator throws this usage exception rather than silently ignoring the flag, to keep script behavior explicit.","triggerScenarios":"Running `bin/bulk export ... --output - --overwrite`. $is_overwrite is true from --overwrite, $is_stdout is true when --output equals '-', and that exact combination throws before any query runs.","commonSituations":"Scripts templated from a file-export command where --overwrite was already present; users switching the destination from a file to stdout by editing only the path value.","solutions":["Remove --overwrite from the command when using --output -.","Keep a file destination (--output <path>) if you actually want overwrite behavior.","Build the flag list programmatically so --overwrite is only appended for file destinations."],"exampleFix":"# before\nbin/bulk export --query all --output - --overwrite\n# after\nbin/bulk export --query all --output -","handlingStrategy":"validation","validationCode":"# only add --overwrite for file destinations\nflags=(--query \"$QUERY\" --output \"$DEST\")\nif [[ \"$DEST\" != '-' && \"$ALLOW_OVERWRITE\" == 1 ]]; then\n  flags+=(--overwrite)\nfi\nbin/bulk export \"${flags[@]}\"","typeGuard":null,"tryCatchPattern":"Catch PhutilArgumentUsageException in PHP tooling and treat the message text as user-facing guidance: print it verbatim and exit with a usage error code.","preventionTips":["Derive --overwrite from the destination type instead of hardcoding it.","Document in shared scripts that --overwrite is file-only.","Smoke-test script templates once against stdout before scheduling them."],"tags":["phabricator","cli","export","flags"],"backgroundTag":"conflicting-cli-flags","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}