Skip to content

Commit

Permalink
chore: Tell why a coverage report can't be parsed (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
aconrad authored May 26, 2024
1 parent 9aefb8d commit b0a3a21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Release Notes

## Unreleased
* Improve error message as to why parsing the Cobertura report failed.

## 3.3.1 (2024-02-17)
* Fix total stmts, miss and cover values in the coverage report when an ignore
Expand Down
14 changes: 12 additions & 2 deletions pycobertura/cobertura.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,27 @@ def __init__(self, report, filesystem=None):
source files referenced in the report. Please check the
`pycobertura.filesystem` module to learn more about filesystems.
"""
errors = []
for load_func in [
self._load_from_file,
self._load_from_string,
]:
try:
self.xml = load_func(report)
break
except BaseException:
except BaseException as e:
errors.append(e)
pass
else:
raise self.InvalidCoverageReport("Invalid coverage file: {}".format(report))
raise self.InvalidCoverageReport(
"""\
Invalid coverage report: {}.
The following exceptions occurred while attempting to parse the report:
* While treating the report as a filename: {}.
* While treating the report as an XML Cobertura string: {}""".format(
report, errors[0], errors[1]
)
)

self.filesystem = filesystem
self.report = report
Expand Down

0 comments on commit b0a3a21

Please sign in to comment.