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

parse(text = ) before evaluating, so that we can catch parse errors #4

Merged
merged 3 commits into from
Oct 5, 2023

Conversation

romainfrancois
Copy link
Contributor

The idea is to be able to catch parse errors before we try to evaluate, I've tried to do this through the internal R_ParseVector() function, but unfortunately because of how things are implemented in R, this does not give access to error messages, so instead this use an R call behind a tryCatch() , i.e. if the cell [7] has 1+1 this will evaluate :

tryCatch(parse(text = "1+1", srcfile = "<cell [7]>"), error = identity) 

so that we either get

  • some expression(s) to evaluate:
> parse(text = "rnorm(10) ; 2")
expression(rnorm(10), 2)
  • some error to propagate:
> tryCatch(parse(text = "1 |> 2", srcfile = "<cell [7]>"), error = identity)
<RHSnotFnCall in 2: The pipe operator requires a function call as RHS (<input>:1:6)>
>
>
> tryCatch(parse(text = "1++", srcfile = "<cell [7]>"), error = identity)
<simpleError in parse(text = "1++", srcfile = "<cell [7]>"): <cell [7]>:2:0: fin d'entrée inattendue
1: 1++
   ^>
> tryCatch(parse(text = "foo()2", srcfile = "<cell [7]>"), error = identity)
<simpleError in parse(text = "foo()2", srcfile = "<cell [7]>"): <cell [7]>:1:6: constante numérique inattendue
1: foo()2
         ^>
image

This PR does not handle yet the case when the expression does parse, it just echoes. Will do in a follow up

@romainfrancois romainfrancois merged commit f4fdee3 into main Oct 5, 2023
2 of 3 checks passed
@romainfrancois romainfrancois deleted the execute_request_impl branch October 5, 2023 12:52
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.

1 participant