{"record":{"id":"0fec509e6b7d5dc0","repo":"phacility/phabricator","slug":"failed-to-write-d-byte-s-to-s","errorCode":null,"errorMessage":"Failed to write %d byte(s) to \"%s\".","messagePattern":"Failed to write (.+?) byte\\(s\\) to \"(.+?)\"\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/infrastructure/storage/management/workflow/PhabricatorStorageManagementRenamespaceWorkflow.php","lineNumber":174,"sourceCode":"      foreach ($lines as $line) {\n\n        foreach ($patterns as $key => $pattern) {\n          if (preg_match($pattern, $line, $matches)) {\n            $line = $matches[1].$to.$matches[3];\n            $found[$key]++;\n          }\n        }\n\n        $data = $line.\"\\n\";\n\n        if ($is_compress) {\n          $bytes = gzwrite($file, $data);\n        } else {\n          $bytes = fwrite($file, $data);\n        }\n\n        if ($bytes !== strlen($data)) {\n          throw new Exception(\n            pht(\n              'Failed to write %d byte(s) to \"%s\".',\n              new PhutilNumber(strlen($data)),\n              $output_name));\n        }\n      }\n\n      if ($is_compress) {\n        $ok = gzclose($file);\n      } else {\n        $ok = fclose($file);\n      }\n\n      if ($ok !== true) {\n        throw new Exception(\n          pht(\n            'Failed to close file \"%s\".',\n            $output_file));","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementRenamespaceWorkflow.php#L156-L192","documentation":"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.","triggerScenarios":"`--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`).","commonSituations":"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.","solutions":["Check space with `df -h <output-dir>` and free room; a full-database dump can be several times the live data size.","Point --output at a roomier volume, or write beside the input dump (that volume already held it).","If piping stdout, make sure the consumer reads until EOF; remove `| head`-style shortcuts.","Re-run the whole command after making space — the partial output was already removed."],"exampleFix":"# before: output to a nearly full volume\n./bin/storage renamespace --input d.sql --from a --to b --output /tmp/out.sql\n\n# after: output to a volume with headroom\n./bin/storage renamespace --input d.sql --from a --to b --output /mnt/bigdisk/out.sql","handlingStrategy":"try-catch","validationCode":"free_kb=$(df -k \"$(dirname \"$OUT\")\" | tail -1 | awk '{print $4}')\n[ \"$free_kb\" -gt 1048576 ] || { echo 'less than 1GiB free for output; aborting' >&2; exit 2; }","typeGuard":null,"tryCatchPattern":"try {\n  // run the renamespace workflow\n} catch (Exception $ex) {\n  // the workflow already removed the partial output file\n  fwrite(STDERR, $ex->getMessage().\"\\n\");\n  exit(1);\n}","preventionTips":["Check df -h before any dump-sized write.","Write output next to the input dump, which already fit on that volume.","Never pipe renamespace stdout into head or another short-lived consumer."],"tags":["phabricator","bin-storage","renamespace","disk-full","file-io","truncated-write"],"backgroundTag":"short-write-disk-full","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}