phacility/phabricator · error · HeraldInvalidConditionException

The regular expression pair "%s" is not valid JSON. Enter a

Error message

The regular expression pair "%s" is not valid JSON. Enter a valid JSON array with two elements.

What it means

Thrown by HeraldAdapter::willSaveCondition() for the 'regular expression pair' condition type (CONDITION_REGEXP_PAIR). The condition value must be a JSON array holding two regular expressions (one for the key, one for the value, used for matching object key/value pairs); phutil_json_decode() throws PhutilJSONParserException when the string is not valid JSON, and Herald wraps that in HeraldInvalidConditionException. Any JSON syntax error — single quotes, trailing commas, unescaped quotes — produces this error.

Source

Thrown at src/applications/herald/adapter/HeraldAdapter.php:635

    switch ($condition_type) {
      case self::CONDITION_REGEXP:
      case self::CONDITION_NOT_REGEXP:
        $ok = @preg_match($condition_value, '');
        if ($ok === false) {
          throw new HeraldInvalidConditionException(
            pht(
              'The regular expression "%s" is not valid. Regular expressions '.
              'must have enclosing characters (e.g. "@/path/to/file@", not '.
              '"/path/to/file") and be syntactically correct.',
              $condition_value));
        }
        break;
      case self::CONDITION_REGEXP_PAIR:
        $json = null;
        try {
          $json = phutil_json_decode($condition_value);
        } catch (PhutilJSONParserException $ex) {
          throw new HeraldInvalidConditionException(
            pht(
              'The regular expression pair "%s" is not valid JSON. Enter a '.
              'valid JSON array with two elements.',
              $condition_value));
        }

        if (count($json) != 2) {
          throw new HeraldInvalidConditionException(
            pht(
              'The regular expression pair "%s" must have exactly two '.
              'elements.',
              $condition_value));
        }

        $key_regexp = array_shift($json);
        $val_regexp = array_shift($json);

        $key_ok = @preg_match($key_regexp, '');

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Enter the value as a strict JSON array of two strings: ["@key-pattern@", "@value-pattern@"].
  2. Use double quotes only; single quotes are never valid JSON.
  3. Escape any double quote inside the patterns as \".
  4. Verify with a JSON linter (echo '...' | jq .) before pasting into the condition box.

Example fix

// before
['@^Differential.*@', '@^closed@']

// after
["@^Differential.*@", "@^closed@"]
Defensive patterns

Strategy: validation

Validate before calling

// Decode the pair before attempting to save the condition
try {
  $json = phutil_json_decode($value);
} catch (PhutilJSONParserException $ex) {
  // reject the form value; never reach willSaveCondition()
  return pht('Regexp pair must be valid JSON, e.g. ["@a@", "@b@"]');
}

Type guard

function isHeraldRegexpPairString($value) {
  if (!is_string($value)) {
    return false;
  }
  try {
    phutil_json_decode($value);
    return true;
  } catch (PhutilJSONParserException $ex) {
    return false;
  }
}

Try / catch

try {
  $editor->save();
} catch (HeraldInvalidConditionException $ex) {
  // the message names the exact bad pair; show it next to the
  // condition row and keep the rest of the user's input intact
}

Prevention

When it happens

Trigger: Saving a Herald rule with a 'regexp pair' condition whose value is not parseable JSON, e.g. ['@key@', '@val@'] (single quotes), "@key@", "@val@" without the array brackets, a trailing comma, or an unescaped quote inside a pattern. The value is decoded with phutil_json_decode() before the two regexes are extracted and validated.

Common situations: Users hand-write the pair in the condition box using JavaScript-ish or shell-ish quoting instead of strict JSON. Copying from a terminal where quotes got mangled, or editing a previously saved rule and deleting a bracket or comma.

Related errors


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