Skip to content

Exception Handling #137

Closed
Closed

Description

@lorenzwalthert

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.

Activity

  1. krlmlr commented on Aug 19, 2017

    @krlmlr
    Member

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

  2. lorenzwalthert commented on Aug 20, 2017

    @lorenzwalthert
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions