oraios/serena · error · ValueError

end_line must be -1 or >= start_line, got {end_line} < {star

Error message

end_line must be -1 or >= start_line, got {end_line} < {start_line}

What it means

_validate_text_document_diagnostics_request requires the requested line range to be coherent: end_line may be -1 (meaning 'to end of file') or must be >= start_line. Otherwise a ValueError is raised because a range ending before it starts cannot yield meaningful diagnostics.

Source

Thrown at src/solidlsp/ls.py:820

    ) -> 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,
        relative_file_path: str,
        start_line: int = 0,

View on GitHub (pinned to 7fcbca7e62)

Solutions

  1. Ensure end_line is -1 (whole file) or >= start_line
  2. Swap arguments if start/end were accidentally reversed
  3. Guard computed ranges: end = max(start, end) or use -1 for open-ended ranges

Example fix

// before
ls.request_text_document_diagnostics("src/a.py", 10, 5, 3)
// after
ls.request_text_document_diagnostics("src/a.py", 5, 10, 3)  # or end_line=-1 for EOF
Defensive patterns

Strategy: validation

Validate before calling

if end_line != -1 and end_line < start_line:
    start_line, end_line = end_line, start_line  # or set end_line = -1

Prevention

When it happens

Trigger: Calling request_text_document_diagnostics / request_published_text_document_diagnostics / get_cached_published_text_document_diagnostics with an end_line other than -1 that is smaller than start_line (e.g. swapped arguments or wrong sentinel).

Common situations: Swapping start/end parameters at the call site; passing -1 to start_line instead of end_line; computing end_line from an empty/short span.

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


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