phacility/phabricator · error · Exception

Failed to open output file "%s" for writing.

Error message

Failed to open output file "%s" for writing.

What it means

Renamespace could not open its destination for writing: fopen($output_file, 'wb') or, with `--compress`, gzopen returned false, so the workflow throws before writing anything. Typical causes are a missing parent directory, permission denied, a path naming a directory, or a read-only filesystem. A generic Exception is thrown and the command aborts; the handler then tries to remove the output path, which is harmless at this stage.

Source

Thrown at src/infrastructure/storage/management/workflow/PhabricatorStorageManagementRenamespaceWorkflow.php:139

      $lines = new LinesOfALargeExecFuture($future);
    } else {
      $lines = new LinesOfALargeFile($input);
    }

    if ($output_file === null) {
      $file = fopen('php://stdout', 'wb');
      $output_name = pht('stdout');
    } else {
      if ($is_compress) {
        $file = gzopen($output_file, 'wb');
      } else {
        $file = fopen($output_file, 'wb');
      }
      $output_name = $output_file;
    }

    if (!$file) {
      throw new Exception(
        pht(
          'Failed to open output file "%s" for writing.',
          $output_name));
    }

    $name_pattern = preg_quote($from, '@');

    $patterns = array(
      'use' => '@^(USE `)('.$name_pattern.')(_.*)$@',
      'create' => '@^(CREATE DATABASE /\*.*?\*/ `)('.$name_pattern.')(_.*)$@',
    );

    $found = array_fill_keys(array_keys($patterns), 0);

    try {
      $matches = null;
      foreach ($lines as $line) {

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Create and permission the parent directory: `mkdir -p $(dirname $OUT)`, then retry.
  2. Verify writability as the same user (`touch $OUT`); if it fails, fix ownership or write under /tmp.
  3. Use an absolute path to rule out cwd and relative-path confusion.
  4. If gzopen fails with --compress, drop --compress and gzip afterwards: pipe stdout through `gzip -c > out.sql.gz`.

Example fix

# before
./bin/storage renamespace --live --from a --to b --output /srv/exports/out.sql

# after
mkdir -p /srv/exports && chown $(id -un) /srv/exports
./bin/storage renamespace --live --from a --to b --output /srv/exports/out.sql
Defensive patterns

Strategy: validation

Validate before calling

out_dir=$(dirname "$OUT")
[ -d "$out_dir" ] || { echo "missing directory: $out_dir" >&2; exit 2; }
[ -w "$out_dir" ] || { echo "not writable: $out_dir" >&2; exit 2; }

Prevention

When it happens

Trigger: `--output /missing/dir/out.sql` where the parent directory does not exist; an unwritable directory (permissions or ownership); `--output` naming a directory; with `--compress`, an environment where gzopen fails.

Common situations: Outputting into a directory that was never created (for example /srv/exports); running as a user without write access to a root-owned path; typos in long absolute paths; SELinux denying writes to the target context.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/533dc5594557e6a4. Report an issue: GitHub.