Fix the gemspec error snippet on Windows drive-letter paths - #9668
Merged
Conversation
Bundler::DSLError#to_s read the offending line number from
`trace_line.split(":")[1]`. On Windows the backtrace path carries a drive
letter such as `C:`, so that field is the path rather than the number, and
the negative index that follows garbles the source snippet. Match the number
that sits right before `:in` or the end of the line instead.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Bundler’s Bundler::DSLError#to_s source-snippet rendering when the Gemfile/gemspec backtrace path contains a Windows drive letter (e.g., C:). Previously, the code extracted the line number via a naive split(":") index, which breaks on drive-letter paths and can produce a garbled/incorrect snippet.
Changes:
- Update
Bundler::DSLError#to_sto extract the line number using a regex that targets the:<line>segment immediately before:in(or end-of-line), avoiding the drive-letter colon. - Re-enable the existing runtime spec on Windows by removing the
skipguard for the gemspec LoadError snippet expectation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
spec/runtime/setup_spec.rb |
Removes the Windows-only skip so the gemspec LoadError snippet behavior is exercised on Windows. |
lib/bundler/dsl.rb |
Fixes line-number parsing from backtrace lines so DSLError#to_s renders the correct offending source line on Windows drive-letter paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hsbt
added a commit
that referenced
this pull request
Jul 10, 2026
Fix the gemspec error snippet on Windows drive-letter paths (cherry picked from commit 4781616)
hsbt
added a commit
that referenced
this pull request
Jul 10, 2026
Fix the gemspec error snippet on Windows drive-letter paths (cherry picked from commit 4781616)
hsbt
added a commit
that referenced
this pull request
Jul 10, 2026
Fix the gemspec error snippet on Windows drive-letter paths (cherry picked from commit 4781616)
hsbt
added a commit
that referenced
this pull request
Jul 10, 2026
Fix the gemspec error snippet on Windows drive-letter paths (cherry picked from commit 4781616)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bundler::DSLError#to_s renders the offending source line when a Gemfile or gemspec raises. It read the line number from
trace_line.split(":")[1], which assumes the path before it carries no colon. On Windows the backtrace path starts with a drive letter such asC:, so that field is a slice of the path rather than the number, and the negative index it produces garbles the snippet.This reads the number that sits right before
:inor at the end of the backtrace line instead, so the drive-letter colon is ignored. The result is unchanged on platforms without drive letters.Forward port of ruby/ruby#17615.