oraios/serena · error · InvalidTextLocationError

{line=}, {col=}

Error message

{line=}, {col=}

What it means

InvalidTextLocationError with the offending line/col raised by FileUtils.get_index_from_line_col (src/solidlsp/ls_utils.py:235) when the requested line number is beyond the last line of the text, so stepping to that line fails.

Source

Thrown at src/solidlsp/ls_utils.py:235

        :param text: the text in which the index is to be located
        :param index: the 0-based index in the text
        :return: the 0-based line number corresponding to the index in the text
        """
        return cls.get_line_col_from_index(text, index)[0]

    @staticmethod
    def get_index_from_line_col(text: str, line: int, col: int) -> int:
        """
        :param text: the text in which the coordinates are to be located
        :param line: the 0-based line number
        :param col: the 0-based column number
        :return: the corresponding 0-based index in the text
        """
        # step over full lines until the requested line is reached
        text_stepper = TextStepper(text)
        while text_stepper.line < line:
            if not text_stepper.step_line():
                raise InvalidTextLocationError(f"{line=}, {col=}")

        return text_stepper.line_start_idx + col

    @staticmethod
    def _get_updated_position_from_line_and_column_and_edit(l: int, c: int, text_to_be_inserted: str) -> tuple[int, int]:
        """
        :param l: the 0-based line number before the edit
        :param c: the 0-based column number before the edit
        :param text_to_be_inserted: the text that was inserted at the given position
        :return: the updated 0-based line and column numbers after the edit (end of insertion)
        """
        text_stepper = TextStepper(text_to_be_inserted)
        text_stepper.process_all()
        if text_stepper.line > 0:
            l += text_stepper.line
            c = text_stepper.col
        else:
            c += text_stepper.col

View on GitHub (pinned to 7fcbca7e62)

Solutions

  1. Validate line < number of lines before conversion, clamping to the last line for appends.
  2. Recompute positions from the current document state.
  3. Verify 0-based line/col conventions across the integration.

Example fix

// before
idx = FileUtils.get_index_from_line_col(text, 1000, 0)
// after
line = min(line, len(text.splitlines()) - 1)
idx = FileUtils.get_index_from_line_col(text, line, col)
Defensive patterns

Strategy: validation

Validate before calling

def valid_line(text: str, line: int) -> bool:
    return 0 <= line < len(text.splitlines())

Type guard

def clamp_line(text: str, line: int) -> int:
    return max(0, min(line, len(text.splitlines()) - 1))

Try / catch

try:
    idx = FileUtils.get_index_from_line_col(text, line, col)
except InvalidTextLocationError:
    idx = len(text)

Prevention

When it happens

Trigger: Calling get_index_from_line_col(text, line, col) (directly or via insert_text_at_position, get_text_in_range, delete_text_between_positions) with a line >= number of lines in the document.

Common situations: LSP positions from another (longer) document version applied to the current text; appends computed with line == len(lines) instead of the last valid 0-based index; range values from external tools.

Related errors


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