oraios/serena · error

Invalid glob brace expression in {pattern!r}: empty braces a

Error message

Invalid glob brace expression in {pattern!r}: empty braces are not allowed

What it means

TextUtils._expand_braces expands glob brace expressions like src/*.{py,txt}. When the innermost {...} group matched by the regex is empty ({}), it raises ValueError because empty braces are a malformed brace expression, referencing the original pattern.

Source

Thrown at src/serena/util/text_utils.py:229

    def _tostring_includes(self) -> list[str]:
        return ["_glob_expr"]

    @staticmethod
    def _expand_braces(pattern: str) -> list[str]:
        """
        Expands brace patterns in a glob string.
        For example, "**/*.{js,jsx,ts,tsx}" becomes ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"].
        Handles multiple brace sets as well.
        """
        patterns = [pattern]
        while any("{" in p or "}" in p for p in patterns):
            new_patterns = []
            for p in patterns:
                match = re.search(r"\{([^{}]*)\}", p)
                if match:
                    options_expr = match.group(1)
                    if not options_expr:
                        raise ValueError(f"Invalid glob brace expression in {pattern!r}: empty braces are not allowed")

                    prefix = p[: match.start()]
                    suffix = p[match.end() :]
                    options = options_expr.split(",")
                    for option in options:
                        new_patterns.append(f"{prefix}{option}{suffix}")
                else:
                    raise ValueError(f"Invalid glob brace expression in {pattern!r}: unmatched brace")
            patterns = new_patterns
        return patterns

    @staticmethod
    def _translate_glob_to_regex(pattern: str) -> str:
        res = []
        i = 0
        n = len(pattern)
        while i < n:
            c = pattern[i]

View on GitHub (pinned to 7fcbca7e62)

Solutions

  1. Remove the empty braces or replace with a valid alternation like {a,b}
  2. If you meant a literal brace, escape it appropriately or use a pattern without braces
  3. Validate/interpolate template placeholders before building the glob
  4. Catch ValueError and report the offending pattern to the user

Example fix

// before
pattern = 'src/**/{}/*.py'
// after
pattern = 'src/**/*.py'  # or 'src/**/{a,b}/*.py'
Defensive patterns

Strategy: validation

Validate before calling

def has_empty_braces(pattern: str) -> bool:
    return "{}" in pattern
if has_empty_braces(glob):
    raise ValueError("glob contains empty braces {}")

Try / catch

try:
    results = TextUtils.search_text(pat, source_file_path=f)
except ValueError as e:
    if "empty braces" in str(e):
        pat = pat.replace("{}", "")
    else:
        raise

Prevention

When it happens

Trigger: Passing a glob pattern containing '{}' (empty braces) to any API that constructs a GlobPattern/_expand_braces — e.g. search_for_text_overflow patterns or path filters with a typo like 'src/**/{}/*.py'.

Common situations: Editor variables left unexpanded (template placeholders like {} not substituted); copy-pasted glob patterns with dangling braces; f-string formatting mistakes producing {}.

Related errors


AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29). Data as JSON: /api/errors/6d64e47e458453a8. Report an issue: GitHub.