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
- Enter the value as a strict JSON array of two strings: ["@key-pattern@", "@value-pattern@"].
- Use double quotes only; single quotes are never valid JSON.
- Escape any double quote inside the patterns as \".
- 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
- Always author regexp pairs through a JSON-aware editor or builder, never freehand text.
- Pipe the value through `echo "$PAIR" | jq .` (or json_decode in PHP) before pasting it into Herald.
- Remember JSON requires double quotes; single quotes are the most common cause of this error.
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
- The regular expression pair "%s" must have exactly two eleme
- The regular expression "%s" is not valid. Regular expression
- The first regexp in the regexp pair, "%s", is not a valid re
- The second regexp in the regexp pair, "%s", is not a valid r
- Unknown condition "%s"!
AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21).
Data as JSON: /api/errors/c14c7f468bb99bae.
Report an issue: GitHub.