Python Ruff IllegalArgumentException: 33 is not a valid line offset for pointer, with repro

Error importing Python Ruff data

I don’t think this is a false positive but a bug in the importer for Ruff. But maybe I just have something wrong in my environment or similar.

It seems the importer is mixing the data from the start of the error (line and column) and the end (line and column).

Environment

Language: Python
Using Ruff to import errors (announced here: 9 New Python Rules & Support for Ruff Reports)
SonarQube: Developer Edition - Version 10.2.1 (build 78527)
SonarQube: Scan GitHub Action: sonarsource/sonarqube-scan-action@v2.0.1
Ruff version: 0.0.292

Replication

With this Python file in app/drunk.py:

data = [{"engaged_ratio": 1}]


def process():
    engaged_ratio_values_list = list(
        map(lambda data_point: data_point["engaged_ratio"], data)
    )
    return engaged_ratio_values_list

Run Ruff with:

$ ruff --output-format json --exit-zero app/drunk.py

That outputs something like:

[
  {
    "code": "C417",
    "end_location": {
      "column": 6,
      "row": 7
    },
    "filename": "/Users/user/acme/code/acme-project/app/drunk.py",
    "fix": {
      "applicability": "Suggested",
      "edits": [
        {
          "content": "[data_point[\"engaged_ratio\"] for data_point in data]",
          "end_location": {
            "column": 6,
            "row": 7
          },
          "location": {
            "column": 33,
            "row": 5
          }
        }
      ],
      "message": "Replace `map` with a `list` comprehension"
    },
    "location": {
      "column": 33,
      "row": 5
    },
    "message": "Unnecessary `map` usage (rewrite using a `list` comprehension)",
    "noqa_row": 5,
    "url": "https://docs.astral.sh/ruff/rules/unnecessary-map"
  }
]

…replace acme-project with your GitHub data. This is because Ruff exports absolute paths and SonarQube can’t import them.

The GitHub Action could then instead have something like:

$ ruff --output-format json --exit-zero app/drunk.py | sed 's/\/home\/runner\/work\/acme-project\/acme-project\///g' | tee common/ruff-report.json

The GitHub Action fails to import the data with:

INFO: Sensor Import of Ruff issues [python]
INFO: Importing /github/workspace/common/ruff-report.json
ERROR: No issues information will be saved as the report file '/github/workspace/common/ruff-report.json' can't be read. IllegalArgumentException: 33 is not a valid line offset for pointer. File app/drunk.py has 5 character(s) at line 7
INFO: Sensor Import of Ruff issues [python] (done) | time=10ms

If you check the error, it’s complaining about column 33, which is in the (start) location, but in row 7, which is in the end_location.

I suspect the current importer is mixing the data from the start location and the end_location instead of only reading from the start location (or understanding the end_location as a separate point).

Hi @tiangolo,

Thank you very much for reporting this issue! There is a bug when importing the report. I have created this ticket in order to track our progress.

Thank you again!

Best regards,

David

1 Like

I see that it is reported as done in [SONARPY-1533] - Jira, that’s great! :tada:

What is the process for getting that new version? Is it released as part of the next SonarQube? What is the right place to track the availability of that fix?

Hi @tiangolo,

Yes, the ticket was done and it will be part of SonarQube 10.3 which should be released next week.
Once the new version of SonarQube is out an announcement will be made here.
Thank you again for reporting this issue!

Best regards,

David