oraios/serena · error · ValueError
No symbol declaration found at the location of the regex mat
Error message
No symbol declaration found at the location of the regex match. Location: {relative_path}:{coords.line}:{coords.col}. What it means
find_symbol by regex/coordinate flow locates a regex match in a file, then asks the language server for the symbol declaration at that position. If the language server reports no defining symbol at the match's line/column, the tool raises this ValueError.
Source
Thrown at src/serena/tools/symbol_tools.py:453
coords = find_text_coordinates(content, regex, require_unique=True)
assert coords is not None
else:
symbol = symbol_retriever.find_unique(name_path_pattern=containing_symbol_name_path, within_relative_path=relative_path)
body_line_numers = symbol.get_body_line_numbers_or_raise()
content = editor.read_file(relative_path, lines=body_line_numers)
coords = find_text_coordinates(content, regex, require_unique=True)
assert coords is not None
coords.line += body_line_numers[0]
# retrieve declaration
defining_symbol = symbol_retriever.find_declaration(
relative_file_path=relative_path,
line=coords.line,
column=coords.col,
include_body=include_body,
)
if defining_symbol is None:
raise ValueError(
f"No symbol declaration found at the location of the regex match. Location: {relative_path}:{coords.line}:{coords.col}."
)
# create output
symbol_dict = self._defining_symbol_to_result_dict(
symbol_retriever,
defining_symbol,
include_body,
include_info,
)
result = self._to_json(symbol_dict)
return result
@staticmethod
def _defining_symbol_to_result_dict(
symbol_retriever: Any,
defining_symbol: LanguageServerSymbol,
include_body: bool,View on GitHub (pinned to 7fcbca7e62)
Solutions
- Tighten the regex so matches land on actual symbol identifiers/declarations
- Re-run the search immediately before symbol lookup so coordinates are current
- Verify the file is in an LS-supported language and the symbol is a real declaration, not a comment/string
- Fall back to find_symbol with a name_path_pattern instead of coordinate-based lookup
Example fix
// before pattern = 'def' # matches the word anywhere, incl. comments // ValueError: No symbol declaration found at ... // after pattern = r'def\s+my_function\b' # match lands on the actual symbol
Defensive patterns
Strategy: try-catch
Validate before calling
m = regex.search(text)
line = text.count('\n', 0, m.start()) + 1
col = m.start() - text.rfind('\n', 0, m.start())
# ensure match lands on an identifier, not comments/strings:
if text[m.start():m.end()] not in identifiers_of_file(text):
raise SkipToolCall('regex match is not a symbol') Try / catch
try:
sym = find_symbol_by_regex_tool.apply(regex=pattern, ...)
except ValueError as e:
if 'No symbol declaration found' in str(e):
sym = find_symbol_tool.apply(name_path_pattern=extract_identifier(pattern))
else:
raise Prevention
- Anchor regexes to symbol declarations (e.g. r'def\\s+name\\b'), not bare keywords
- Re-read the file right before coordinate lookup to avoid stale positions
- Prefer name_path_pattern lookup over regex-coordinate lookup when possible
When it happens
Trigger: The regex matches text that is not a symbol declaration/usage the LS recognizes (comments, strings, keywords, generated code without LS support); the match's coordinates are stale after the file changed; the file's language has no active language server.
Common situations: Regex like 'def |class ' catching decorators or docstrings; file edited between pattern search and symbol lookup so line:col now lands elsewhere; searching in a file type the LS can't index.
Related errors
- Cannot extract symbols from file {relative_path}. Active lan
- FindSymbolTool returned no results
- Invalid language server: '{orig_language_str}'.\nValid value
- The language server manager is not initialized, indicating a
- name_path_pattern must not be empty or contain only wildcard
AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29).
Data as JSON: /api/errors/598430963f2f9920.
Report an issue: GitHub.