oraios/serena · error · ValueError
start_line must be non-negative, got {start_line}
Error message
start_line must be non-negative, got {start_line} What it means
Before querying diagnostics, SolidLSP validates arguments in _validate_text_document_diagnostics_request. A negative start_line is invalid because LSP positions are 0-based line numbers, so a ValueError('start_line must be non-negative, ...') is raised.
Source
Thrown at src/solidlsp/ls.py:818
end_line: int,
min_severity: int,
) -> list[ls_types.Diagnostic]:
diagnostics = [d for d in diagnostics if cls._diagnostic_matches_range(d, start_line, end_line)]
diagnostics = [d for d in diagnostics if cls._diagnostic_matches_min_severity(d, min_severity)]
return diagnostics
def _validate_text_document_diagnostics_request(
self,
relative_file_path: str,
start_line: int,
end_line: int,
min_severity: int,
) -> str:
if not self.server_started:
log.error("request_text_document_diagnostics called before Language Server started")
raise SolidLSPException("Language Server not started")
if start_line < 0:
raise ValueError(f"start_line must be non-negative, got {start_line}")
if end_line != -1 and end_line < start_line:
raise ValueError(f"end_line must be -1 or >= start_line, got {end_line} < {start_line}")
if min_severity not in {1, 2, 3, 4}:
raise ValueError(f"min_severity must be one of 1, 2, 3, 4, got {min_severity}")
return pathlib.Path(str(PurePath(self.repository_root_path, relative_file_path))).as_uri()
def get_published_diagnostics_generation(self, relative_file_path: str) -> int:
"""
Get the generation number for the latest published diagnostics of a file.
:param relative_file_path: The relative path of the file.
:return: the generation number, or ``-1`` if none were published yet.
"""
uri = pathlib.Path(str(PurePath(self.repository_root_path, relative_file_path))).as_uri()
return self._get_published_diagnostics_generation(uri)
def get_cached_published_text_document_diagnostics(
self,View on GitHub (pinned to 7fcbca7e62)
Solutions
- Pass a 0-based, non-negative start_line (first line is 0)
- Use end_line=-1 to indicate 'to end of file' instead of a negative start_line
- Validate/clamp user- or computed-provided line numbers before calling
Example fix
// before
ls.request_text_document_diagnostics("src/a.py", -1, -1, 3)
// after
ls.request_text_document_diagnostics("src/a.py", 0, -1, 3) Defensive patterns
Strategy: validation
Validate before calling
assert isinstance(start_line, int) and start_line >= 0, f"start_line must be >= 0, got {start_line}" Prevention
- Remember LSP lines are 0-based; first line is 0
- Use end_line=-1 (not negative start_line) for 'whole file'
- Clamp computed positions: start_line = max(0, start_line)
When it happens
Trigger: Calling request_text_document_diagnostics / request_published_text_document_diagnostics / get_cached_published_text_document_diagnostics with start_line < 0 (e.g. -1 used as a sentinel, or an unsigned conversion bug).
Common situations: Passing -1 to mean 'whole file' (the sentinel is end_line, not start_line); converting unsigned LSP positions with signed overflow; uninitialized/default-initialized position variables.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- min_severity must be one of 1, 2, 3, 4, got {min_severity}
- end_line must be -1 or >= start_line, got {end_line} < {star
- Language Server not started
- Unknown language '{lang}'. Supported: {all_langs}
- Cannot edit external file: {relative_path}
AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29).
Data as JSON: /api/errors/db44c9f928fa4231.
Report an issue: GitHub.