oraios/serena · error · ValueError
Symbol location does not contain a valid position in a file
Error message
Symbol location does not contain a valid position in a file
What it means
find_referencing_symbols_by_location needs an absolute position (file + line + column) to ask the language server for references. If the passed LanguageServerSymbolLocation lacks a position in file, it raises this ValueError instead of sending a malformed request.
Source
Thrown at src/serena/symbol.py:857
exclude_kinds: Sequence[SymbolKind] | None = None,
) -> list[ReferenceInLanguageServerSymbol]:
"""
Find all symbols that reference the symbol at the given location.
:param symbol_location: the location of the symbol for which to find references.
Does not need to include an end_line, as it is unused in the search.
:param include_body: whether to include the body of all symbols in the result.
Not recommended, as the referencing symbols will often be files, and thus the bodies will be very long.
Note: you can filter out the bodies of the children if you set include_children_body=False
in the to_dict method.
:param include_kinds: an optional sequence of ints representing the LSP symbol kind.
If provided, only symbols of the given kinds will be included in the result.
:param exclude_kinds: If provided, symbols of the given kinds will be excluded from the result.
Takes precedence over include_kinds.
:return: a list of symbols that reference the given symbol
"""
if not symbol_location.has_position_in_file():
raise ValueError("Symbol location does not contain a valid position in a file")
assert symbol_location.relative_path is not None
assert symbol_location.line is not None
assert symbol_location.column is not None
lang_server = self.get_language_server(symbol_location.relative_path)
references = lang_server.request_referencing_symbols(
relative_file_path=symbol_location.relative_path,
line=symbol_location.line,
column=symbol_location.column,
include_imports=False,
include_self=False,
include_body=include_body,
include_file_symbols=True,
)
if include_kinds is not None:
references = [s for s in references if s.symbol["kind"] in include_kinds]
if exclude_kinds is not None:View on GitHub (pinned to 7fcbca7e62)
Solutions
- Check symbol_location.has_position_in_file() before calling and skip or re-resolve symbols without positions
- Obtain the location from a full symbol lookup (find_unique) rather than partial search data
- Supply line/column explicitly if you know the definition site
Example fix
// before
refs = mgr.find_referencing_symbols_by_location(loc) # loc has no position
// after
if loc.has_position_in_file():
refs = mgr.find_referencing_symbols_by_location(loc) Defensive patterns
Strategy: type-guard
Validate before calling
if not symbol_location.has_position_in_file():
raise SkipSymbol("location lacks line/column") Type guard
def is_located(loc) -> bool:
return loc.has_position_in_file() and loc.relative_path is not None Try / catch
try:
refs = mgr.find_referencing_symbols_by_location(loc)
except ValueError as e:
if "valid position in a file" in str(e):
refs = re_resolve_and_find_refs(loc)
else:
raise Prevention
- Derive locations from find_unique/full symbol lookups, not partial search results
- Skip references lookups for symbols without positions
- Confirm the language server populates selection ranges for the language in use
When it happens
Trigger: Constructing a location from a symbol whose position is None (e.g. module-level symbols, references without ranges) and passing it to find_referencing_symbols/get_symbol_diagnostics_by_location.
Common situations: Using a location obtained from a stale or non-definitional symbol; hand-building a LanguageServerSymbolLocation from search results that omitted line/column; language servers that return no selection range for certain constructs.
Related errors
- Project '{project_root_or_name}' is not registered with Sere
- Tool '{req.tool_name}' is not read-only and cannot be execut
- Body start position is not defined for {self}
- Body end position is not defined for {self}
- Body line numbers could not be determined for {self.get_name
AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29).
Data as JSON: /api/errors/ae9a5f750def6113.
Report an issue: GitHub.