ryanluker / vscode-coverage-gutters

Display test coverage generated by lcov and xml - works with many languages
https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters
MIT License
460 stars 88 forks source link

Cannot read property 'lines' of undefined #354

Closed reganheath closed 2 years ago

reganheath commented 2 years ago

I have coverage gutters v2.9.1

I am generating code coverage for Erlang using rebar3, then converting the output to Cobertura using https://github.com/covertool/covertool.

The top of the stack is.. [1643108745489][coverageparser][cobertura-parse]: Stacktrace: TypeError: filename: //Dev/game/X/_build/test/covertool/X.covertool.xml Cannot read property 'lines' of undefined at extractLcovStyleBranches (/***/.vscode-server/extensions/ryanluker.vscode-coverage-gutters-2.9.1/node_modules/cobertura-parse/source/index.js:30:12) at //.vscode-server/extensions/ryanluker.vscode-coverage-gutters-2.9.1/node_modules/cobertura-parse/source/index.js:77:24 at Array.map (:null:null) at unpackage (//.vscode-server/extensions/ryanluker.vscode-coverage-gutters-2.9.1/node_modules/cobertura-parse/source/index.js:75:20) at //.vscode-server/extensions/ryanluker.vscode-coverage-gutters-2.9.1/node_modules/cobertura-parse/source/index.js:134:22 at Parser. (//.vscode-server/extensions/ryanluker.vscode-coverage-gutters-2.9.1/node_modules/xml2js/lib/parser.js:303:18)

Which, I believe, indicates that the c (class) object passed to extractLcovStyleBranches is undefined. Which seems to indicate that the array returned by classesFromPackages has included an 'undefined' element.

I checked classesFromPackages, and compared to the XML I have, which looks like (cut down, removed identifiers, etc)

<coverage timestamp="1643107972566" line-rate="0.564" lines-covered="1598" lines-valid="2832" branch-rate="0.0" branches-covered="0" branches-valid="0" complexity="0" version="1.9.4.1">
  <sources>
      ...
  </sources>
  <packages>
    <package name="X" line-rate="0.0" branch-rate="0.0" complexity="0">
      <classes/>
    </package>
    <package name="P" line-rate="0.026" branch-rate="0.0" complexity="0">
      <classes>
        <class name="C" filename="..." line-rate="0.026" branch-rate="0.0" complexity="0">
          <methods>
            <method name="M" signature="S/5" line-rate="0.0" branch-rate="0.0">
              <lines>
                <line number="145" hits="0" branch="False"/>
                ...
              </lines>
            </method>
          </methods>
          <lines>
            <line number="15" hits="0" branch="False"/>
             ...
          </lines>
        </class>
      </classes>
    </package>
    ...
  </packages>
</coverage>

If I remove all the packages with no classes, e.g.

<package name="X" line-rate="0.0" branch-rate="0.0" complexity="0">
  <classes/>
</package>

Then it works without error.

ryanluker commented 2 years ago

@reganheath Thanks for the issue, I will try to dig into it for yeah soon.

To give you something high level to try out, I know cobertura has been annoying for some to get working, so if you are able to use lcov or clover formats for coverage instead... that would be preferable. https://github.com/ryanluker/vscode-coverage-gutters/blob/master/src/files/coverageparser.ts#L1-L4

I also found this person setup with erlang and the extension with a lcov generate they built. I am no erlang expert though so it might not work with rebar3 🤔 . https://elixirforum.com/t/lcovex-lcov-file-generator-for-elixir-projects/32057

Maybe that will help?

reganheath commented 2 years ago

@ryanluker Hi, thanks. No rush on this. GitLab itself handles the coverage data, so we've got that and I can easily write a small script to clean it up for coverage gutters. Thanks!

ryanluker commented 2 years ago

@reganheath I might close this ticket then as eventually Cobertura will be deprecated given it isn't maintained anymore and will slowly rot... https://github.com/vokal/cobertura-parse Most of the issues that show up like this are due to bugs not being fixed in the upstream package.

We even had to pin the package to a specific commit to get what we needed 😓 . https://github.com/ryanluker/vscode-coverage-gutters/blob/master/package.json#L281

If we could find a different js / ts package for consuming Cobertura style coverage... then we should definitely switch to that!

ryanluker commented 2 years ago

@reganheath I believe this is fixed with https://github.com/ryanluker/vscode-coverage-gutters/pull/360 possibly. Keep an eye out for this fix in the 2.10.0 release, otherwise we can always open this ticket again if it didn't help.

reganheath commented 2 years ago

@ryanluker Hi, unfortunately the bug persists in v2.10.1 unchanged (same stack, same cause, same result).

reganheath commented 2 years ago

I have created a patch: https://github.com/fschwaiger/cobertura-parse/pull/1

ryanluker commented 2 years ago

@reganheath Thanks for the heads up! Once it is merged in the upstream repo we can update the version here, and it will go out in the next release.

ryanluker commented 2 years ago

@reganheath Upstream is merged, so we just need to update the commit hash, do you have an example file we can use to simulate the error and test that it has been fixed?

reganheath commented 2 years ago

Any file with a package with no classes will do, e.g. `

`

ryanluker commented 2 years ago

@reganheath This will be fixed in the 2.11.0 release!

ryanluker commented 2 years ago

@reganheath I just saw that 2.11.0 has a bunch of stuff in it already 😅 if this upcoming release ends up taking longer than a month to finish, I will do a smaller release to get this stuff out and into the marketplace store.

ryanluker commented 1 year ago

@reganheath sorry for the delay, 2.10.2 is going out now and includes the cobertura fix.