Skip to content

Exception Handling #137

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

Closed
lorenzwalthert opened this issue Aug 19, 2017 · 2 comments · Fixed by #139
Closed

Exception Handling #137

lorenzwalthert opened this issue Aug 19, 2017 · 2 comments · Fixed by #139

Comments

@lorenzwalthert
Copy link
Collaborator

lorenzwalthert commented Aug 19, 2017

When working on #58, I tried this

styler::style_text("call(x), { } ")
#> Error in parse(text = text, keep.source = TRUE): <text>:1:8: unexpected ','
#> 1: call(x),
#>            ^

This is not particuarly useful but one can guess the root of the problem. If you want to style a file that contains such an invalid expression, you get

style_dir("tests/testthat/public-api/xyzdir/subdir/")
Error in if (!any(ret)) { : missing value where TRUE/FALSE needed
In addition: Warning message:
 Show Traceback
 ...

How should we handle these cases? I don't have experience in error handling in packages so @krlmlr can you advise? Should we implement before submitting to CRAN? Also related to assertive tests etc.

@krlmlr
Copy link
Member

krlmlr commented Aug 19, 2017

Can we wrap a tryCatch() around the parse() call?

@lorenzwalthert
Copy link
Collaborator Author

Yes, but I think that's not very informative if you don't know which file is the problem. Maybe we add an argument assert_code to transform_files() and if set, we try parsing before executing the styling and return an informative error message if parsing fails for one of the files.

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 a pull request may close this issue.

2 participants