Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
omercnet opened this issue Dec 4, 2023 · 22 comments · Fixed by #304

Comments

@omercnet
Copy link

omercnet commented Dec 4, 2023

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

@ewjoachim
Copy link
Member

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
Copy link
Member

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 ewjoachim reopened this Dec 5, 2023
@omercnet
Copy link
Author

omercnet commented Dec 5, 2023

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 🤷‍♀️

@ewjoachim
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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

@ewjoachim
Copy link
Member

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.

@gegoune
Copy link

gegoune commented Apr 11, 2024

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]

@ewjoachim ewjoachim reopened this Apr 11, 2024
@ewjoachim
Copy link
Member

ewjoachim commented Apr 11, 2024

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

@gegoune
Copy link

gegoune commented Apr 11, 2024

      - 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.

@ewjoachim
Copy link
Member

Have you tried with:

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

?

@gegoune
Copy link

gegoune commented Apr 12, 2024

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

@ewjoachim
Copy link
Member

ewjoachim commented Apr 17, 2024

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

@gegoune
Copy link

gegoune commented Apr 18, 2024

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

@ewjoachim
Copy link
Member

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

@kernelsam
Copy link

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.

@ewjoachim
Copy link
Member

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.

@gegoune
Copy link

gegoune commented Nov 7, 2024

I have solved my issue reported in #303 (comment).
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!

@ewjoachim
Copy link
Member

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

@dmitry-olefir-snkeos
Copy link

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).

@ewjoachim
Copy link
Member

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

@ewjoachim ewjoachim reopened this Nov 11, 2024
@dmitry-olefir-snkeos
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants