Skip to content

fix(cobertura): handle malformed XML in Int() function - #1987

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/cobertura-malformed-xml-int
Open

fix(cobertura): handle malformed XML in Int() function#1987
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/cobertura-malformed-xml-int

Conversation

@sentry

@sentry sentry Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

This PR addresses issue WORKER-YJ6, a ValueError occurring when parsing malformed Cobertura XML reports.

Problem:
The Int() helper function in apps/worker/services/report/languages/cobertura.py was not robust enough to handle severely malformed string inputs for coverage hits (e.g., '79<line number='). While it caught the initial ValueError from int(value), the fallback int(float(value)) would then raise an uncaught ValueError if the string was unparseable by float().

This malformed input originates from corrupted Cobertura XML where XML tag text appears to bleed into attribute values, indicating an issue with the upstream XML generation or parsing.

Solution:

  1. Harden Int() function: The Int() function has been updated to catch both ValueError and TypeError for both int() and int(float()) conversion attempts. If conversion fails, it now returns None.
  2. Graceful handling of None: Call sites for Int() within CoberturaProcessor (for both <line> and <statement> elements) now check if Int() returns None. If so, the specific line or statement is skipped, preventing further processing of invalid data and allowing the rest of the report to be processed without error.

Legal Boilerplate

Look, I get it. The entity doing business as "Codecov" is owned by Harness, Inc. In 2026 Harness acquired Codecov and as a result Harness is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Harness can use, modify, copy, and redistribute my contributions, under Harness's choice of terms.

Fixes WORKER-YJ6

@thomasrockhu-codecov

Copy link
Copy Markdown
Contributor

🤖 Harness AI Code Review in progress… · View results →

@codecov-notifications

codecov-notifications Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
apps/worker/services/report/languages/cobertura.py 55.55% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.62%. Comparing base (a8ec2db) to head (fb8ce44).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
apps/worker/services/report/languages/cobertura.py 55.55% 4 Missing ⚠️

❌ Your patch check has failed because the patch coverage (55.55%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1987      +/-   ##
==========================================
- Coverage   91.63%   91.62%   -0.01%     
==========================================
  Files        1336     1336              
  Lines       53230    53237       +7     
  Branches     1647     1647              
==========================================
+ Hits        48778    48781       +3     
- Misses       4131     4135       +4     
  Partials      321      321              
Flag Coverage Δ
workerintegration 58.47% <11.11%> (-0.02%) ⬇️
workerunit 90.53% <55.55%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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 this pull request may close these issues.

1 participant