phacility/phabricator · error · Exception

Failed to write %d byte(s) to "%s".

Error message

Failed to write %d byte(s) to "%s".

What it means

A write to the destination returned fewer bytes than requested (fwrite/gzwrite result !== strlen($data)), and the workflow throws rather than emit a truncated dump. The usual causes are the filesystem filling mid-run, a quota being hit, or — when writing to stdout — the downstream reader closing the pipe. The surrounding catch deletes the partial output file, so failed runs leave no half-written dump.

Source

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

      foreach ($lines as $line) {

        foreach ($patterns as $key => $pattern) {
          if (preg_match($pattern, $line, $matches)) {
            $line = $matches[1].$to.$matches[3];
            $found[$key]++;
          }
        }

        $data = $line."\n";

        if ($is_compress) {
          $bytes = gzwrite($file, $data);
        } else {
          $bytes = fwrite($file, $data);
        }

        if ($bytes !== strlen($data)) {
          throw new Exception(
            pht(
              'Failed to write %d byte(s) to "%s".',
              new PhutilNumber(strlen($data)),
              $output_name));
        }
      }

      if ($is_compress) {
        $ok = gzclose($file);
      } else {
        $ok = fclose($file);
      }

      if ($ok !== true) {
        throw new Exception(
          pht(
            'Failed to close file "%s".',
            $output_file));

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Check space with `df -h <output-dir>` and free room; a full-database dump can be several times the live data size.
  2. Point --output at a roomier volume, or write beside the input dump (that volume already held it).
  3. If piping stdout, make sure the consumer reads until EOF; remove `| head`-style shortcuts.
  4. Re-run the whole command after making space — the partial output was already removed.

Example fix

# before: output to a nearly full volume
./bin/storage renamespace --input d.sql --from a --to b --output /tmp/out.sql

# after: output to a volume with headroom
./bin/storage renamespace --input d.sql --from a --to b --output /mnt/bigdisk/out.sql
Defensive patterns

Strategy: try-catch

Validate before calling

free_kb=$(df -k "$(dirname "$OUT")" | tail -1 | awk '{print $4}')
[ "$free_kb" -gt 1048576 ] || { echo 'less than 1GiB free for output; aborting' >&2; exit 2; }

Try / catch

try {
  // run the renamespace workflow
} catch (Exception $ex) {
  // the workflow already removed the partial output file
  fwrite(STDERR, $ex->getMessage()."\n");
  exit(1);
}

Prevention

When it happens

Trigger: `--output` on a volume that runs out of space or hits quota partway through the dump; or piping stdout into a command that exits early (for example `| head`).

Common situations: Renaming a large production dump onto a nearly full /tmp or home partition; small container or VM root disks; piping output through gzip with a downstream failure.

Related errors


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