codeclimate / test-reporter

Code Climate Test Reporter
MIT License
156 stars 76 forks source link

cobertura report Index out of range #320

Open foulkesjohn opened 6 years ago

foulkesjohn commented 6 years ago

I have a cobertura coverage file which is crashing because of the following class:

I'm running format-coverage -t cobertura -d ./cobertura.xml

<class name="MyClass.h" filename="app/MyClass.h" line-rate="1.0000000000000000" branch-rate="1.0000000000000000" complexity="0.0">
  <methods/>
  <lines>
    <line number="3" branch="false" hits="166"/>
    <line number="4" branch="false" hits="166"/>
    <line number="5" branch="false" hits="166"/>
    <line number="0" branch="false" hits="3"/>
    <line number="0" branch="false" hits="4"/>
    <line number="0" branch="false" hits="5"/>
    <line number="0" branch="false" hits="3"/>
    <line number="0" branch="false" hits="4"/>
    <line number="0" branch="false" hits="5"/>
    <line number="0" branch="false" hits="3"/>
    <line number="0" branch="false" hits="4"/>
    <line number="0" branch="false" hits="5"/>
    <line number="0" branch="false" hits="3"/>
    <line number="0" branch="false" hits="4"/>
    <line number="0" branch="false" hits="5"/>
    <line number="0" branch="false" hits="3"/>
    <line number="0" branch="false" hits="4"/>
    <line number="0" branch="false" hits="5"/>
    <line number="0" branch="false" hits="3"/>
    <line number="0" branch="false" hits="4"/>
    <line number="0" branch="false" hits="5"/>
    <line number="0" branch="false" hits="3"/>
    <line number="0" branch="false" hits="4"/>
    <line number="0" branch="false" hits="5"/>
    <line number="0" branch="false" hits="3"/>
    <line number="0" branch="false" hits="4"/>
    <line number="0" branch="false" hits="5"/>
  </lines>
</class>

Stacktrace:

panic: runtime error: index out of range

goroutine 1 [running]:
github.com/codeclimate/test-reporter/formatters/cobertura.Formatter.Format(0x7ffeefbff584, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /src/github.com/codeclimate/test-reporter/formatters/cobertura/cobertura.go:82 +0xa8e
github.com/codeclimate/test-reporter/formatters/cobertura.(*Formatter).Format(0xc420134020, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        <autogenerated>:1 +0x9f
github.com/codeclimate/test-reporter/cmd.CoverageFormatter.Save(0x7ffeefbff584, 0xf, 0x1780600, 0xc420134020, 0x7ffeefbff577, 0x9, 0x154033f, 0x19, 0xc420018064, 0x20, ...)
        /src/github.com/codeclimate/test-reporter/cmd/format-coverage.go:107 +0x4c
github.com/codeclimate/test-reporter/cmd.runFormatter(0x7ffeefbff584, 0xf, 0x1780600, 0xc420134020, 0x7ffeefbff577, 0x9, 0x154033f, 0x19, 0xc420018064, 0x20, ...)
        /src/github.com/codeclimate/test-reporter/cmd/format-coverage.go:103 +0x2fe
github.com/codeclimate/test-reporter/cmd.glob..func4(0x17b8d80, 0xc420017cc0, 0x1, 0x4, 0x0, 0x0)
        /src/github.com/codeclimate/test-reporter/cmd/format-coverage.go:65 +0x5e
github.com/codeclimate/test-reporter/vendor/github.com/spf13/cobra.(*Command).execute(0x17b8d80, 0xc420017c00, 0x4, 0x4, 0x17b8d80, 0xc420017c00)
        /src/github.com/codeclimate/test-reporter/vendor/github.com/spf13/cobra/command.go:644 +0x3f2
github.com/codeclimate/test-reporter/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x17b8fc0, 0x0, 0xc42010e8a0, 0xc420134040)
        /src/github.com/codeclimate/test-reporter/vendor/github.com/spf13/cobra/command.go:734 +0x339
github.com/codeclimate/test-reporter/vendor/github.com/spf13/cobra.(*Command).Execute(0x17b8fc0, 0x1537712, 0x9)
        /src/github.com/codeclimate/test-reporter/vendor/github.com/spf13/cobra/command.go:693 +0x2b
github.com/codeclimate/test-reporter/cmd.Execute()
        /src/github.com/codeclimate/test-reporter/cmd/root.go:62 +0x2d
main.main()
        /src/github.com/codeclimate/test-reporter/main.go:20 +0x20

This is probably bad data generated from slather but causes the crash non the less. If I manually remove all the number=0 lines then it works.

efueger commented 6 years ago

@chrishulton -

I have another user who has the same error message.

  - run:
      name: Code Climate post-build
      command: ./cc-test-reporter after-build --coverage-input-type cobertura --exit-code $?
prnewman commented 6 years ago

I can confirm what @foulkesjohn said. The error occurs if there's a line number="0" in cobertura.xml:

            <line number="100" branch="false" hits="15000"/>
            <line number="0" branch="false" hits="100"/>
            <line number="101" branch="false" hits="150"/>

Another workaround is to use --debug to locate that file and ignore it in .slather.yml

chrishulton commented 6 years ago

Thanks for reporting the issue. We have added a fix to the test reporter to ignore the line number="0" lines so they will not crash the service.

It looks like the underlying issue is being worked on in Slather as well: https://github.com/SlatherOrg/slather/pull/387

Let us know if you continue to see issues after upgrading to the latest version of the reporter (0.5.2).