Skip to content

R: browser detection isn't working right in some cases #2310

@DavisVaughan

Description

@DavisVaughan

For example, when you hit the force(x) line, it exits debug mode even though we clearly are still in it:

fn <- function(x = if (1) 2 else 3) {
  1 + 1
  force(x)
  2 + 2
  3 + 3
}
debugonce(fn)
fn()
Screen.Recording.2024-02-22.at.10.46.17.AM.mov

Another example is with tryCatch()

eval(parse(text = "fn <- function() {
  tryCatch(
  {
    1 + 1
    2 + 2
    3 + 3
  }
  )
}", keep.source = FALSE))

debugonce(fn)
fn()

and really anything that adds frames to the intermediate stack

tryCatchLike <- function(expr) {
  onTheStack <- function(expr) {
    expr
  }
  onTheStack(expr)
}

eval(parse(text = "fn <- function() {
  tryCatchLike(
  {
    1 + 1
    2 + 2
    3 + 3
  }
  )
}
", keep.source = FALSE))

debugonce(fn)

fn()

I did a little digging, and I think this bit of prompt_info() isn't working right

https://github.com/posit-dev/amalthea/blob/de55465ee31efd7ca40c1b762e7141a2efa74286/crates/ark/src/interface.rs#L741-L755

In the case of the tryCatch, there are 3 frames on the stack at the time when we erroneously exited debug mode, which looked like:

Screenshot 2024-02-21 at 5 04 59 PM

i.e. note that frame 3 is actually from the try-catch, not our code, so its environment doesn't have RDEBUG() set. So this heuristic is probably not quite right!

I'm not entirely sure what the right fix is here, so I'll probably have to rely on @lionel- for this one

Metadata

Metadata

Labels

area: kernelsIssues related to Jupyter kernels and LSP serverslang: r

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions