phacility/phabricator · error · Exception

Field "data" must be non-empty.

Error message

Field "data" must be non-empty.

What it means

differential.setdiffproperty stores a named property on a diff; data must be a non-empty JSON-encoded string, because the method json_decode()s it right after this check. Null or a zero-length string is rejected before anything is stored.

Source

Thrown at src/applications/differential/conduit/DifferentialSetDiffPropertyConduitAPIMethod.php:35

      'name'    => 'required string',
      'data'    => 'required string',
    );
  }

  protected function defineReturnType() {
    return 'void';
  }

  protected function defineErrorTypes() {
    return array(
      'ERR_NOT_FOUND' => pht('Diff was not found.'),
    );
  }

  protected function execute(ConduitAPIRequest $request) {
    $data = $request->getValue('data');
    if ($data === null || !strlen($data)) {
      throw new Exception(pht('Field "data" must be non-empty.'));
    }

    $diff_id = $request->getValue('diff_id');
    if ($diff_id === null) {
      throw new Exception(pht('Field "diff_id" must be non-null.'));
    }

    $name = $request->getValue('name');
    if ($name === null || !strlen($name)) {
      throw new Exception(pht('Field "name" must be non-empty.'));
    }

    $data = json_decode($data, true);

    self::updateDiffProperty($diff_id, $name, $data);
  }

  private static function updateDiffProperty($diff_id, $name, $data) {

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Always JSON-encode the payload: json_encode($value) yields non-empty text even for empty containers ('{}' or '[]').
  2. Guard before the call: if data is null or strlen(data) is 0, skip the call or default to '{}'.
  3. Confirm you send a string, not a raw array or null.

Example fix

// before
$params = array(
  'diff_id' => $diff_id,
  'name' => 'arc:lint',
  'data' => $data, // $data may be null or ''
);

// after
$payload = ($value === null) ? new stdClass() : $value;
$params = array(
  'diff_id' => $diff_id,
  'name' => 'arc:lint',
  'data' => json_encode($payload), // always a non-empty string
);
Defensive patterns

Strategy: validation

Validate before calling

$data = json_encode($payload);
if (!is_string($data) || strlen($data) === 0) {
  throw new InvalidArgumentException(
    'Property payload must encode to a non-empty string.');
}
$params['data'] = $data;

Type guard

function isEncodablePayload($value) {
  $json = json_encode($value);
  return is_string($json) && strlen($json) > 0;
}

Try / catch

try {
  $client->callMethodSynchronous('differential.setdiffproperty', $params);
} catch (ConduitClientException $ex) {
  if (strpos($ex->getMessage(), '"data" must be non-empty') !== false) {
    // rebuild payload with json_encode() and retry once
  } else {
    throw $ex;
  }
}

Prevention

When it happens

Trigger: Sending data as null or '' — commonly a payload built from empty input, a raw array sent where the API expects a string, or a default empty-string value that was never replaced.

Common situations: Callers that pass arrays directly instead of json_encode()ing them; code paths that compute the property payload from empty collections; scripts that only fill in name and diff_id.

Related errors


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