Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C stack error are not caught #103

Closed
cderv opened this issue Nov 2, 2021 · 5 comments
Closed

C stack error are not caught #103

cderv opened this issue Nov 2, 2021 · 5 comments

Comments

@cderv
Copy link
Collaborator

cderv commented Nov 2, 2021

I don't know if this is possible or not but currently we have this

> evaluate::evaluate("stop('a')")
[[1]]
$src
[1] "stop('a')"

attr(,"class")
[1] "source"

[[2]]
<simpleError in eval(expr, envir, enclos): a>

> evaluate::evaluate('e <- new.env()
+                    attr(e, "e") <- e
+                    object.size(e)')
Error: C stack usage  15922884 is too close to the limit

This was reported in tidyverse/reprex#388

@yihui
Copy link
Collaborator

yihui commented Nov 2, 2021

try() works in these two cases:

try(object.size(e), silent = T)
try(withCallingHandlers(object.size(e)), silent = T)

but not in this one when an error handler is present:

try(withCallingHandlers(object.size(e), error = function(e) NULL), silent = T)

I don't know why yet.

@jennybc
Copy link
Member

jennybc commented Nov 8, 2021

Saw this today:
https://twitter.com/R_dev_news/status/1457626456301846533

Stack overflow errors are now signaled as errors inheriting from class ‘stackOverflowError’. See ‘?stackOverflowError’ for more details.

@yihui
Copy link
Collaborator

yihui commented Nov 8, 2021

Great! It seems we can just wait for the next release of R. Thanks for the info!

@hadley
Copy link
Member

hadley commented Jan 11, 2024

While stackoverflow errors are now caught:

e <- new.env()
attr(e, "e") <- e
tryCatch(object.size(e), error = function(err) err)
#> <CStackOverflowError: C stack usage  7953636 is too close to the limit>

Created on 2024-01-11 with reprex v2.0.2.9000

And evaluate now "works", it still doesn't actually capture the error:

evaluate::evaluate('
  e <- new.env()
  attr(e, "e") <- e
  object.size(e)'
)
#> [[1]]
#> $src
#> [1] "\n"
#> 
#> attr(,"class")
#> [1] "source"
#> 
#> [[2]]
#> $src
#> [1] "  e <- new.env()\n"
#> 
#> attr(,"class")
#> [1] "source"
#> 
#> [[3]]
#> $src
#> [1] "  attr(e, \"e\") <- e\n"
#> 
#> attr(,"class")
#> [1] "source"
#> 
#> [[4]]
#> $src
#> [1] "  object.size(e)"
#> 
#> attr(,"class")
#> [1] "source"

Created on 2024-01-11 with reprex v2.0.2.9000

This is likely due to the special nature of stackoverflow errors (because the stack is "full", it's hard to run any additional code wrapped around the error, so will likely require some careful extra handling).

@hadley hadley changed the title C stack error are not catched C stack error are not caught Jan 11, 2024
@hadley
Copy link
Member

hadley commented Jun 14, 2024

I'm pretty sure it's not possible to capture this error in evaluate itself

@hadley hadley closed this as completed Jun 14, 2024
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

No branches or pull requests

4 participants