Skip to content

fix: debugSource error when keep.source is FALSE #12375 - #18686

Closed
AzazelSensei wants to merge 16 commits into
rstudio:mainfrom
AzazelSensei:fix/debugsource-keep-source-12375
Closed

AzazelSensei wants to merge 16 commits into
rstudio:mainfrom
AzazelSensei:fix/debugsource-keep-source-12375

Conversation

@AzazelSensei

@AzazelSensei AzazelSensei commented Aug 29, 2026 •

Copy link
Copy Markdown

Intent

debugSource() warns when options(keep.source = FALSE) because parse() leaves srcref NULL and makeSourceEquivFunction() still calls structure() on it. #12375

Approach

.rs.makeSourceEquivFunction() returns early in two places:

  • right after parse(), when the file has no expressions (empty or comment-only). Before, 1:length(content) iterated with i = 1 and failed with subscript out of bounds.
  • after the expressions are copied into fun, when length(refs) == 0. With keep.source = FALSE, parse() leaves srcref NULL, and the old code failed with attempt to set an attribute on NULL. Only the source-reference metadata is skipped, so the file still runs; breakpoints have no effect without srcrefs.

Automated Tests

Two tests in src/cpp/tests/testthat/test-debugger.R call .rs.makeSourceEquivFunction() on:

  • a one-line file with keep.source = FALSE, checking that it still runs and assigns into the target environment
  • empty and comment-only files, with keep.source both on and off

Run with ./build/src/cpp/rstudio-tests --scope r --filter debugger.

QA Notes

Not yet checked by hand in RStudio. The new tests fail against main's SessionBreakpoints.R and pass with this change. To check manually, run the reporter's snippet; it should print Hello, world! with no error:

options(keep.source = FALSE)
rfile <- tempfile(fileext = ".R")
writeLines("print('Hello, world!')", con = rfile)
debugSource(rfile)

Also run debugSource() on an empty file and on a file containing only a comment, with keep.source on and off; each should finish without error.

Documentation

NEWS.md under Fixed.

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards
  • A reviewer is assigned to this PR (if unsure who to assign, check Area Owners list)
  • This PR passes all local unit tests

parse() leaves srcref NULL in that case, and structure(NULL, *) warned
from makeSourceEquivFunction.
@gtritchie gtritchie added this to the 2026.09 (Autumn Hawkbit) milestone Aug 29, 2026
@gtritchie
gtritchie requested a review from kevinushey August 29, 2026 19:10
@gtritchie

Copy link
Copy Markdown
Member

Thanks for the PR, we'll take a look at it as soon as we can.

If you haven't already, please fill out and submit the contributor agreement: https://github.com/rstudio/rstudio/blob/main/CONTRIBUTING.md#contributing-code.

Return early on a length-0 parse so 1:length(content) does not run,
and treat a missing srcref the same as an empty one.
@AzazelSensei

Copy link
Copy Markdown
Author

Took the empty-file early return after parse, and switched the srcref guard to length(refs) == 0. Left out the message() so the #12375 path stays quiet. Agreed on the srcfile skip — that attr is NULL when keep.source is FALSE. Updated NEWS and the title from warns to errors.

@gtritchie
gtritchie deployed to e2e-playwright September 16, 2026 20:47 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 16, 2026 20:47 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 16, 2026 20:50 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 16, 2026 20:50 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 16, 2026 20:58 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 16, 2026 20:58 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 16, 2026 21:00 — with GitHub Actions Active
@gtritchie
gtritchie deployed to e2e-playwright September 16, 2026 21:00 — with GitHub Actions Active
@gtritchie

gtritchie commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

I don't think we've received your contributor agreement (but please correct me if I'm wrong!).

@gtritchie

gtritchie commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Oh, actually, I should be able to make the fixes directly on your fork, if the settings allow it. I'll check that.

Update: done! I've addressed the feedback, fixed merge issues, etc.

So once I've got confirmation of your CLA submission we should be good to go.

@kevinushey kevinushey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No actionable findings at 056bd25471a17a352cae11447c6ed44c2165c742.

The early returns preserve execution when source references are unavailable and safely handle empty or comment-only files. I checked the surrounding debugger execution and breakpoint handling paths.

Validation: the debugger test suite passed all 36 assertions with no warnings or skips, using this PR's R code loaded into the existing session binary. Additional execution checks with warnings treated as errors, including stored breakpoints, also passed.

CI builds were still running at the time of review.

@gtritchie

Copy link
Copy Markdown
Member

Still waiting on the contributor agreement, and code freeze is about to happen so moving this to next milestone.

@kevinushey

Copy link
Copy Markdown
Collaborator

@AzazelSensei wanted to reach out once more about the CLA.

@kevinushey

Copy link
Copy Markdown
Collaborator

Thanks again for this PR, and for pinpointing the empty-file case on top of the reported one. Unfortunately we can't merge contributions without a signed contributor agreement (see CONTRIBUTING.md), and we weren't able to get one here, so we've re-implemented the fix ourselves in #19284, which credits your work. Closing this one in favour of that.

@kevinushey kevinushey closed this Oct 26, 2026
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.

3 participants