Skip to content

Fix the gemspec error snippet on Windows drive-letter paths - #9668

Merged
hsbt merged 1 commit into
masterfrom
claude/affectionate-hawking-705aea
Jul 2, 2026
Merged

Fix the gemspec error snippet on Windows drive-letter paths#9668
hsbt merged 1 commit into
masterfrom
claude/affectionate-hawking-705aea

Conversation

@hsbt

@hsbt hsbt commented Jul 2, 2026

Copy link
Copy Markdown
Member

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 as C:, 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 :in or 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.

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>
Copilot AI review requested due to automatic review settings July 2, 2026 02:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_s to 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 skip guard 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
hsbt merged commit 4781616 into master Jul 2, 2026
111 checks passed
@hsbt
hsbt deleted the claude/affectionate-hawking-705aea branch July 2, 2026 06:10
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants