Skip to content

fix(shared): Handle ValueError in diff_to_json for malformed diff headers - #2156

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/shared-diff-valueerror
Open

fix(shared): Handle ValueError in diff_to_json for malformed diff headers#2156
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/shared-diff-valueerror

Conversation

@sentry

@sentry sentry Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

This PR addresses a ValueError: not enough values to unpack occurring in shared/torngit/base.py within the diff_to_json function.

Problem:
When processing certain malformed diff headers, specifically those where filenames contain spaces (e.g., "${ dir}/definition.yaml"), the _diff.pop(0).split(" b/", 1) operation can return a single-element list. Attempting to unpack this into before, after raises a ValueError. The existing try/except block only caught IndexError, allowing the ValueError to propagate and crash app.tasks.pulls.Sync tasks.

Solution:
Modified the except clause on line 154 of libs/shared/shared/torngit/base.py from except IndexError: to except (IndexError, ValueError):. This change ensures that ValueError exceptions, caused by malformed diff headers, are also caught. The existing fallback logic within the except block (which scans for --- a/ and +++ b/ lines) correctly handles these cases, preventing task crashes and allowing the diff parsing to proceed as intended.

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

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@thomasrockhu-codecov

thomasrockhu-codecov commented Aug 28, 2026

Copy link
Copy Markdown
Contributor
✨ Harness AI Code Review View in Harness →

Risk: LOW

This PR widens the except IndexError: clause in diff_to_json (libs/shared/shared/torngit/base.py:154) to except (IndexError, ValueError):, so malformed diff headers whose filename line lacks a b/ separator no longer crash app.tasks.pulls.Sync. The existing fallback that scans for --- a/ / +++ b/ correctly handles the ValueError case — _diff.pop(0) has already run before .split() raises, so the header lines the fallback needs are still present in _diff. The change is minimal, correctly targeted, and low-risk.

No issues found above the confidence threshold.

@codspeed-hq

codspeed-hq Bot commented Aug 28, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing seer/fix/shared-diff-valueerror (b370e3d) with main (17e0f08)

Open in CodSpeed

@codecov-notifications

codecov-notifications Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
libs/shared/shared/torngit/base.py 0.00% 1 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 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.63%. Comparing base (17e0f08) to head (b370e3d).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
libs/shared/shared/torngit/base.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2156   +/-   ##
=======================================
  Coverage   91.63%   91.63%           
=======================================
  Files        1337     1337           
  Lines       53262    53262           
  Branches     1647     1647           
=======================================
  Hits        48805    48805           
  Misses       4136     4136           
  Partials      321      321           
Flag Coverage Δ
apiunit 93.98% <ø> (ø)
sharedintegration 36.75% <0.00%> (ø)
sharedunit 84.88% <0.00%> (ø)
workerintegration 58.49% <ø> (ø)
workerunit 90.55% <ø> (ø)

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