SeleniumHQ/selenium · error · RuntimeError
Expected exactly one {where} in {BZL_FILE.name}, found {n}
Error message
Expected exactly one {where} in {BZL_FILE.name}, found {n} What it means
Raised by sub_once() in scripts/update_cddl.py when a regex substitution in common/webref_cddl.bzl does not match exactly once. The function uses re.subn() with re.S (dotall) and asserts n == 1. If n == 0, the expected pattern (e.g., _COMMIT assignment, _CDDL_FILES block, _DFNS_FILES block, _BIDI_SPEC_HTML_* assignments) is missing from the .bzl file. If n > 1, there are duplicate patterns and the script cannot determine which to replace.
Source
Thrown at scripts/update_cddl.py:155
return json.loads(r.data)["sha"]
def existing_repo_names(content):
return set(re.findall(r'\(\s*"([a-z0-9_]+)"\s*,\s*"[^"]+\.cddl"', content))
def render_files(var, entries):
lines = [f"{var} = ["]
for name, filename, sha256 in entries:
lines.append(f' ("{name}", "{filename}", "{sha256}"),')
lines.append("]")
return "\n".join(lines)
def sub_once(content, pattern, replacement, where):
content, n = re.subn(pattern, replacement, content, flags=re.S)
if n != 1:
raise RuntimeError(f"Expected exactly one {where} in {BZL_FILE.name}, found {n}")
return content
def update_pin(commit, cddl_entries, dfns_entries, bidi_commit, bidi_sha256):
content = BZL_FILE.read_text()
# Anchor so this does not also match the tail of `_BIDI_SPEC_HTML_COMMIT = "…"`.
content = sub_once(content, r'(?<![A-Z_])_COMMIT = "[0-9a-f]+"', f'_COMMIT = "{commit}"', "_COMMIT assignment")
content = sub_once(
content, r"_CDDL_FILES = \[.*?\n\]", lambda _: render_files("_CDDL_FILES", cddl_entries), "_CDDL_FILES block"
)
content = sub_once(
content, r"_DFNS_FILES = \[.*?\n\]", lambda _: render_files("_DFNS_FILES", dfns_entries), "_DFNS_FILES block"
)
content = sub_once(
content,
r'_BIDI_SPEC_HTML_COMMIT = "[0-9a-f]+"',
f'_BIDI_SPEC_HTML_COMMIT = "{bidi_commit}"',View on GitHub (pinned to aa36b38e69)
Solutions
- Inspect common/webref_cddl.bzl to verify the expected patterns exist: _COMMIT = "...", _CDDL_FILES = [...], _DFNS_FILES = [...], _BIDI_SPEC_HTML_COMMIT = "...", _BIDI_SPEC_HTML_SHA256 = "...".
- If a variable was renamed, update the regex patterns in sub_once() calls in update_cddl.py to match the new names.
- If the file is corrupted, restore it from git (git checkout common/webref_cddl.bzl) and re-run.
- Ensure there is exactly one occurrence of each pattern — remove any duplicates.
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
import re
content = open('common/webref_cddl.bzl').read()
for label, pattern in [
('_COMMIT', r'(?<![A-Z_])_COMMIT = "[0-9a-f]+"'),
('_CDDL_FILES', r'_CDDL_FILES = \[.*?\n\]'),
('_DFNS_FILES', r'_DFNS_FILES = \[.*?\n\]'),
]:
matches = re.findall(pattern, content, flags=re.S)
if len(matches) != 1:
print(f'WARNING: {label} has {len(matches)} matches, expected 1') Type guard
null
Try / catch
null
Prevention
- Do not manually reformat webref_cddl.bzl — the update script relies on specific patterns.
- Run update_cddl.py regularly so the .bzl file stays in sync with the script's expectations.
- If you must edit the .bzl, preserve the variable names and block structure the regexes expect.
When it happens
Trigger: Running update_cddl.py after the webref_cddl.bzl file was manually edited, reformatted, or restructured such that the anchored regex patterns no longer match. Also triggered if someone added a duplicate variable assignment, or if the file was regenerated from scratch without the expected structure.
Common situations: Manual edits to webref_cddl.bzl that changed variable names, formatting, or block structure; merge conflict resolution that altered the file; the .bzl file was deleted or partially truncated; a variable was renamed (e.g., _COMMIT to _WEBREF_COMMIT) making the regex stale.
Related errors
- Expected exactly one webref_cddl_extension use_repo block, f
- Failed to list {CDDL_PATH} at {commit}: HTTP {r.status}
- Failed to download {url}: HTTP {r.status}
- Failed to resolve {repo}@{branch}: HTTP {r.status}
- Download unavailable (HTTP {r.status}): {url}
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/c426e6e323b86656.
Report an issue: GitHub.