python-coverage-comment-action icon indicating copy to clipboard operation
python-coverage-comment-action copied to clipboard

subprocess.CalledProcessError: Command '('coverage', 'json', '-o', '-')' returned non-zero exit status 2.

Open omercnet opened this issue 2 years ago • 17 comments

2023-12-04T14:04:41.0481051Z ##[notice]Starting action
2023-12-04T14:04:41.2909319Z ##[notice]HTTP Request: GET https://api.github.com/repos/descope/python-sdk "HTTP/1.1 200 OK"
2023-12-04T14:04:41.2916256Z ##[notice]Generating comment for PR
2023-12-04T14:04:41.6464808Z ##[error]Critical error. This error possibly occurred because the permissions of the workflow are set incorrectly. You can see the correct setting of permissions here: https://github.com/py-cov-action/python-coverage-comment-action#basic-usage
Otherwise please look for open issues or open one in https://github.com/py-cov-action/python-coverage-comment-action/
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/subprocess.py", line 18, in run
    return subprocess.run(
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('coverage', 'json', '-o', '-')' returned non-zero exit status 2.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 40, in main
    exit_code = action(
                ^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 92, in action
    return process_pr(
           ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/main.py", line 123, in process_pr
    _, coverage = coverage_module.get_coverage_info(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/coverage.py", line 84, in get_coverage_info
    subprocess.run("coverage", "json", "-o", "-", path=coverage_path)
  File "/usr/local/lib/python3.11/site-packages/coverage_comment/subprocess.py", line 27, in run
    raise SubProcessError("\n".join([exc.stdout, exc.stderr])) from exc
coverage_comment.subprocess.SubProcessError: {"meta": {"version": "7.3.2", "timestamp": "2023-12-04T14:04:41.489052", "branch_coverage": false, "show_contexts": false}, "files": {"descope/__init__.py": {"executed_lines": [1, 10, 11, 18, 19], "summary": {"covered_lines": 5, "num_statements": 5, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "descope/_auth_base.py": {"executed_lines": [2, 5, 6, 8, 9], "summary": {"covered_lines": 4, "num_statements": 4, "percent_covered": 100.0, "percent_covered_display": "100", "missing_lines": 0, "excluded_lines": 0}, "missing_lines": [], "excluded_lines": []}, "descope/auth.py": {"executed_lines": [1, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 19, 20, 21, 23, 35, 47, 48, 49, 54, 62, 63, 65, 74, 76, 77, 78, 86, 87, 88, 90, 91, 92, 94, 95, 96, 97, 99, 100, 102, 103, 104, 116, 123, 131, 132, 134, 137, 146, 147, 149, 152, 160, 161, 163, 164, 165, 171, 172, 173, 174, 177, 179, 180, 183, 184, 186, 187, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 208, 210, 212, 213, 214, 220, 221, 225, 227, 228, 229, 235, 236, 240, 242, 243, 244, 250, 251, 255, 257, 258, 259, 260, 266, 267, 268, 269, 273, 274, 275, 276, 282, 283, 287, 288, 292, 295, 296, 297, 298, 302, 303, 304, 306, 307, 308, 309, 315, 316, 317, 318, 319, 325, 326, 327, 333, 334, 335, 340, 342, 343, 344, 350, 352, 353, 355, 356, 358, 364, 366, 372, 374, 375, 376, 377, 378, 379, 384, 385, 386, 387, 388, 393, 395, 396, 399, 400, 403, 404, 407, 410, 414, 415, 416, 419, 424, 428, 433, 435, 438, 440, 442, 449, 450, 451, 452, 453, 454, 455, 458, 459, 463, 465, 466, 473, 475, 481, 485, 486, 487, 489, 490, 491, 492, 493, 494, 495, 498, 501, 507, 508, 509, 510, 516, 517, 518, 522, 523, 524, 528, 529, 530, 532, 533, 541, 543, 544, 551, 552, 559, 560, 566, 567, 569, 572, 573, 579, 580, 583, 585, 588, 595, 597, 598, 600, 601, 603, 609, 610, 616, 617, 618, 620, 626, 628, 647, 648, 649, 650, 651, 652], "summary": {"covered_lines": 269, "num_statements": 288, "percent_covered": 93.40277777777777, "percent_covered_display": "93", "missing_lines": 19, "excluded_lines": 0}, "missing_lines": [16, 17, 50, 51, 389, 391, 502, 534, 545, 589, 621, 629, 630, 636, 637, 641, 642, 645, 653], "excluded_lines": []}, "descope/authmethod/__init__.py": {"executed_lines

https://github.com/descope/python-sdk/actions/runs/7086877486/job/19288591568

I do not think this is a permission error, as permissions are there and it's been working well for a while

looks like the input is truncated by this might be github logs issue and not really

omercnet avatar Dec 04 '23 14:12 omercnet

Indeed, this is probably not a permission issue (this message is there because it used to be the case that most issues were permission issues, but it might not be the case anymore)

I'm not sure the truncating is by GitHub and not by someone else in the stack, but it's hard to say.

I guess one possible way to help debugging would be to output stderr before stdout when there's an issue.

ewjoachim avatar Dec 05 '23 16:12 ewjoachim

I've made a PR that adds logs. You may need to activate debug mode.

Please let me know whether this gives you enough info to solve the issue on your side or if there still is a bug.

Note that I have no idea who ends up truncating the output.

ewjoachim avatar Dec 05 '23 17:12 ewjoachim

https://github.com/descope/python-sdk/actions/runs/7086877486/job/19345603602

##[debug]Command failed: args=('coverage', 'json', '-o', '-') path=PosixPath('.') kwargs={} exc.stderr=''

still no idea 🤷‍♀️

omercnet avatar Dec 05 '23 20:12 omercnet

Ok, so empty stderr, the command stops just like that. (or the stderr is entirely truncated, but... How ? Why ? Who ?)

Could it be a sigkill, like an OOM or something ? I should have displayed the exit code...

ewjoachim avatar Dec 06 '23 15:12 ewjoachim

Made a second attempt. Should be merged in a few minutes. Let's see if the exit code gives us a bit of info on how the process exited. Hoping for a 137 or something. Or maybe a small number but maybe Coverage uses meaningful exit codes (we'll check if it's relevant)

ewjoachim avatar Dec 06 '23 15:12 ewjoachim

So feel free to rerun the CI and check the debug message.

ewjoachim avatar Dec 07 '23 08:12 ewjoachim

Hi, happy new year :) By lack of ideas, and input, I'm going to close this if it's ok with you. Please you or anyone else experiencing the issue: reopen or recreate if relevant. I'll be delighted to try and tackle this again if we have more input for investigating.

ewjoachim avatar Jan 01 '24 23:01 ewjoachim

Hi there! I believe I have ran into the same issue.

##[debug]Command failed: args=('coverage', 'json', '-o', '-') path=PosixPath('.') kwargs={} exc.stderr='' exc.returncode=2

Please let me know what other information I could provide you. Maybe bit of a hint: my source code is actually in src/ subdirectory, perhaps that's what the problem is? I do see the output in form of json further down the log though:

coverage_comment.subprocess.SubProcessError: 
{"meta": {"format": 2, "version": "7.4.4", "timestamp": "2024-04-11T09:20:51.821149", "branch_coverage": true, "show_contexts": false}, "files":  [... continues here, but eventually gets truncated]

gegoune avatar Apr 11 '24 09:04 gegoune

Can you share your configuration from the workflow files (just the relevant parts) ?

ewjoachim avatar Apr 11 '24 10:04 ewjoachim

      - name: Django Tests
        run: coverage run src/manage.py test src/
      - name: Coverage comment
        id: coverage_comment
        uses: py-cov-action/python-coverage-comment-action@v3
        with:
          GITHUB_TOKEN: ${{ github.token }}
      - name: Store Pull Request comment to be posted
        uses: actions/upload-artifact@v4
        if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
        with:
          name: python-coverage-comment-action
          path: python-coverage-comment-action.txt

and the other workflow (to post comment) is just copy and paste from documentation.

gegoune avatar Apr 11 '24 10:04 gegoune

Have you tried with:

        id: coverage_comment
        uses: py-cov-action/python-coverage-comment-action@v3
        with:
          GITHUB_TOKEN: ${{ github.token }}
          COVERAGE_PATH: src/

?

ewjoachim avatar Apr 12 '24 11:04 ewjoachim

Yes, I have. It fails with No data to report.. Please note that previous configuration (without that parameter) finds coverage's data.

gegoune avatar Apr 12 '24 12:04 gegoune

can you share the coverage configuration (from .coveragerc or pyproject.toml or setup.cfg)

ewjoachim avatar Apr 17 '24 22:04 ewjoachim

Sure, version is coverage==7.4.4.

[tool.coverage.run]
branch = true
omit = ['*/migrations/*', 'manage.py', 'wsgi.py']
relative_files = true

[tool.coverage.report]
fail_under = 100
show_missing = true
skip_covered = true

gegoune avatar Apr 18 '24 05:04 gegoune

Ok, I'll try to reproduce on a small example and see if it fails the same way

ewjoachim avatar Apr 18 '24 07:04 ewjoachim

For posterity, I hit this same error, I was just trying to run coverage against a single file in the root of the repo.. I moved it to a src folder, added a blank init.py file and added --cov=src/ to my pytest command and this action ran without error after that.

kernelsam avatar May 08 '24 23:05 kernelsam

Wait, a __init__.py in the src ? That's definitly not something expected. It means your top level package is src (so if you were to import it, it would be import src). It's strage you had to do that.

ewjoachim avatar Jul 05 '24 18:07 ewjoachim

I have solved my issue reported in https://github.com/py-cov-action/python-coverage-comment-action/issues/303#issuecomment-2049286327. I need to apologise to you for wasting your time. Problem was due to the fact that I wasn't actually running coverage prior to invoking your action. Clearly user's mistake. Thank you for all your assistance!

gegoune avatar Nov 07 '24 17:11 gegoune

Well, I wan't very helpful on my side so it's good that you found your issue :)

ewjoachim avatar Nov 10 '24 15:11 ewjoachim

For anyone facing this, I had the same problem. My issue was the coverage package mismatch - coverage pkg I used to generate the .coverage file was different from the one used in the action (minor version was different).

dmitry-olefir-snkeos avatar Nov 11 '24 08:11 dmitry-olefir-snkeos

You had the same error message ? I think we should improve the error message if we can detect this case.

ewjoachim avatar Nov 11 '24 09:11 ewjoachim

You had the same error message ? I think we should improve the error message if we can detect this case.

Yeah,'('coverage', 'json', '-o', '-')' fails and also same exit status I think, that was some months ago. That was somewhat hard to catch, too many possibilities for why this might happen.

dmitry-olefir-snkeos avatar Nov 11 '24 09:11 dmitry-olefir-snkeos