{"record":{"id":"7fdd123619d1cc2f","repo":"phacility/phabricator","slug":"err-bad-diff-7fdd12","errorCode":"ERR_BAD_DIFF","errorMessage":"ERR_BAD_DIFF","messagePattern":"ERR_BAD_DIFF","errorType":"error_code","errorClass":"ConduitException","httpStatus":null,"severity":"error","filePath":"src/applications/differential/conduit/DifferentialCreateRevisionConduitAPIMethod.php","lineNumber":52,"sourceCode":"  protected function defineReturnType() {\n    return 'nonempty dict';\n  }\n\n  protected function defineErrorTypes() {\n    return array(\n      'ERR_BAD_DIFF' => pht('Bad diff ID.'),\n    );\n  }\n\n  protected function execute(ConduitAPIRequest $request) {\n    $viewer = $request->getUser();\n\n    $diff = id(new DifferentialDiffQuery())\n      ->setViewer($viewer)\n      ->withIDs(array($request->getValue('diffid')))\n      ->executeOne();\n    if (!$diff) {\n      throw new ConduitException('ERR_BAD_DIFF');\n    }\n\n    $revision = DifferentialRevision::initializeNewRevision($viewer);\n    $revision->attachReviewers(array());\n\n    $result = $this->applyFieldEdit(\n      $request,\n      $revision,\n      $diff,\n      $request->getValue('fields', array()),\n      $message = null);\n\n    $revision_id = $result['object']['id'];\n\n    return array(\n      'revisionid'  => $revision_id,\n      'uri'         => PhabricatorEnv::getURI('/D'.$revision_id),\n    );","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/differential/conduit/DifferentialCreateRevisionConduitAPIMethod.php#L34-L70","documentation":"Thrown by the differential.createrevision Conduit method. It loads the diff identified by the diffid parameter with a viewer-policy-filtered DifferentialDiffQuery; if no diff is found, ConduitException('ERR_BAD_DIFF') ('Bad diff ID.') is thrown before the new revision is initialized and field edit applied.","triggerScenarios":"Calling differential.createrevision with a diffid that was never created, belongs to an invisible diff, is a revision ID by mistake, or comes from a failed differential.creatediff step whose error the script ignored.","commonSituations":"Two-step scripts (creatediff then createrevision) that continue after the first step failed; passing the revision number instead of the diff id; diff IDs carried over from a staging install to production.","solutions":["Use exactly the 'diffid' value returned by your earlier differential.creatediff call","Check that the creatediff call succeeded before proceeding - abort the script on any error there","Sanity-check the ID with differential.getdiff before creating the revision","Cast diffid to int; never send a 'D'-prefixed value"],"exampleFix":"// before\n$result = $client->callMethodSynchronous('differential.creatediff', $params);\n// creatediff failed earlier; $diffid = 0 from a fallback\n$client->callMethodSynchronous('differential.createrevision', array(\n  'diffid' => $diffid,\n));\n\n// after\n$result = $client->callMethodSynchronous('differential.creatediff', $params);\n$diffid = (int)$result['diffid']; // creatediff returns the real id\n$client->callMethodSynchronous('differential.createrevision', array(\n  'diffid' => $diffid,\n  'fields' => $fields,\n));","handlingStrategy":"validation","validationCode":"// Pipe the creatediff result; abort if it failed.\n$create = $client->callMethodSynchronous('differential.creatediff', $diff_params);\n$diffid = (int)idx($create, 'diffid', 0);\nif ($diffid <= 0) {\n  throw new RuntimeException('creatediff did not return a diffid');\n}","typeGuard":null,"tryCatchPattern":"try {\n  $client->callMethodSynchronous('differential.createrevision',\n    array('diffid' => $diffid, 'fields' => $fields));\n} catch (ConduitClientException $ex) {\n  if ($ex->getErrorCode() === 'ERR_BAD_DIFF') {\n    // diffid invalid: recreate the diff before retrying\n  } else {\n    throw $ex;\n  }\n}","preventionTips":["Chain createrevision directly to the creatediff response","Fail fast when creatediff errors; never substitute a guessed ID","Distinguish revision IDs from diff IDs in variable naming"],"tags":["phabricator","conduit","differential","diff","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}