phacility/phabricator · error · HeraldInvalidConditionException
The first regexp in the regexp pair, "%s", is not a valid re
Error message
The first regexp in the regexp pair, "%s", is not a valid regexp.
What it means
Thrown by HeraldAdapter::willSaveCondition() for CONDITION_REGEXP_PAIR after the JSON array was decoded and had exactly two elements. The first element is shifted off as the key regexp and smoke-tested with @preg_match($key_regexp, ''); a boolean false return (invalid PCRE pattern) raises this error, naming the first (key) regexp specifically.
Source
Thrown at src/applications/herald/adapter/HeraldAdapter.php:655
'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, '');
if ($key_ok === false) {
throw new HeraldInvalidConditionException(
pht(
'The first regexp in the regexp pair, "%s", is not a valid '.
'regexp.',
$key_regexp));
}
$val_ok = @preg_match($val_regexp, '');
if ($val_ok === false) {
throw new HeraldInvalidConditionException(
pht(
'The second regexp in the regexp pair, "%s", is not a valid '.
'regexp.',
$val_regexp));
}
break;
case self::CONDITION_CONTAINS:
case self::CONDITION_NOT_CONTAINS:
case self::CONDITION_IS:View on GitHub (pinned to 5720a38cfe)
Solutions
- Fix the FIRST element of the JSON array so it is a valid PCRE pattern with delimiters, e.g. "@^title$@".
- Escape or change the delimiter if the pattern itself contains it.
- Test the key pattern standalone: php -r 'var_dump(@preg_match("@^title$@", ""));' — it must not print bool(false).
Example fix
// before ["^title$", "@urgent@"] // after ["@^title$@", "@urgent@"]
Defensive patterns
Strategy: validation
Validate before calling
list($key_re, $val_re) = phutil_json_decode($value);
if (@preg_match($key_re, '') === false) {
return pht('First regexp of the pair is invalid; add delimiters.');
} Type guard
function isValidRegexpPairKey($pair_json) {
$json = phutil_json_decode($pair_json);
return @preg_match($json[0], '') !== false;
} Try / catch
try {
$editor->save();
} catch (HeraldInvalidConditionException $ex) {
// 'first regexp ... is not valid' -> fix element 0 only, then resubmit
} Prevention
- Validate BOTH pair elements with @preg_match($re, '') in one pre-save pass; errors 823 and 824 surface one at a time.
- Use a shared regexp sanitizer so key and value patterns are formatted identically.
When it happens
Trigger: Saving a regexp pair like ["title.*", "@value@"] — the first element lacks delimiters, has an unbalanced delimiter, an invalid modifier, or a PCRE syntax error. The second element is validated separately, so this error points only at element zero.
Common situations: Users add delimiters to one element of the pair but not the other, or paste a bare grep-style pattern as the key matcher while correctly formatting the value matcher.
Related errors
- The regular expression "%s" is not valid. Regular expression
- The second regexp in the regexp pair, "%s", is not a valid r
- The regular expression pair "%s" is not valid JSON. Enter a
- The regular expression pair "%s" must have exactly two eleme
- Unknown condition "%s"!
AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21).
Data as JSON: /api/errors/261b1ea72ae4b431.
Report an issue: GitHub.