Skip to content

Conversation

@biru-codeastromer
Copy link
Contributor

What

Prevent a runtime panic in crates/turborepo-scm/src/git.rs when git emits paths that cannot be anchored to the turbo root (e.g. corrupted filenames, non-parent paths) or when git stdout contains non-UTF8 bytes. Instead of unwrap() → crash, errors are surfaced and handled safely by the change detector.

Why

GitHub Actions CI was failing for repositories that contain unusual filenames (Cyrillic / corrupted / non-UTF8). The panic originated in add_files_from_stdout and caused --affected CI runs to crash. This change makes the flow fail-safe: we log the problem and conservatively treat all packages as changed rather than crashing CI.

Summary of changes

crates/turborepo-scm/src/git.rs

  • add_files_from_stdout(...) now returns Result<(), Error> (propagates non-UTF8 via String::from_utf8 and anchoring errors instead of unwrap()).
  • Call sites use ? to propagate the new Result.
  • Minor import cleanup (duplicate fs removed).

crates/turborepo-lib/src/run/scope/change_detector.rs

  • Handle the nested Result<Result<..., InvalidRange>, Error> from SCM::changed_files(...).
  • Added explicit handling for ScmError::Path(...) — log a warning and default to marking all packages changed.
  • Extracted all_packages_changed_due_to_error helper to deduplicate fallback logic and keep code readable.
  • Adjusted debug output for changed files.

Behavior (user-facing / CI)

Instead of panicking on unanchorable or invalid paths:

  • We log a warning explaining that some SCM paths couldn't be processed.
  • We conservatively treat all packages as changed (CI will run everything rather than failing).
  • Non-UTF8 stdout is returned as an error (no lossy conversion), so callers can decide how to react.

Notes

  • RelativeUnixPath::new(line) remains unwrap()-ed by design (git output for the commands used is not expected to include absolute paths). If maintainers want stricter defensive handling, we can change that to return an error and handle it the same way.

Fix #10403

@biru-codeastromer biru-codeastromer requested a review from a team as a code owner November 12, 2025 06:02
@vercel
Copy link
Contributor

vercel bot commented Nov 12, 2025

@biru-codeastromer is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@biru-codeastromer biru-codeastromer changed the title fix(scm/git): avoid panic for unanchorable/non-UTF8 git paths , gracefully handle path errors fix(scm/git): Avoid panic for unanchorable/non-UTF8 git paths , gracefully handle path errors Nov 12, 2025
Copy link
Contributor

@anthonyshew anthonyshew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the PR!

Let's do a hard failure (exit 1) here instead of a warning. My worry is that users will not see the warning, and suddenly start running all of their CI because of one misbehaving file. If that file were to make it to the default branch of the repo, that would result in some dramatic slowdowns in a large enough repo.

Before this PR, the CI run would crash, and the user's code would never be able to make it through CI. So, erroring with a useful message instead of a crash report would be a meaningful DX improvement, while preserving existing behavior.

@biru-codeastromer
Copy link
Contributor Author

Thanks good call. I updated the change detector so SCM path errors now produce a hard failure (exit 1) with a focused, actionable error message on stderr instead of logging a warning and defaulting to “all packages changed”. This makes the failure visible in CI logs and avoids accidentally running full CI due to a stray problematic filename.

Copy link
Contributor

@anthonyshew anthonyshew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read and correct Claude's output before submitting it in a pull request. If you are not able to verify the completeness of the provided implementation because you do not understand it, please do not send a pull request.

The Vercel review is correct. You need to update the PR description.

Additionally, lets add some unit testing in accordance with this fix. Sorry for not mentioning this earlier.

biru-codeastromer and others added 3 commits November 13, 2025 01:26
Removed outdated documentation for the add_files_from_stdout function.
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
@biru-codeastromer
Copy link
Contributor Author

I will be adding the unit test soon

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.

crates/turborepo-scm/src/git.rs panics in GitHub Actions

2 participants