Open alistaire47 opened 4 years ago
@alistaire47 I think it would be useful to group your issues with milestones so people can tell the difference between issues that are "steps toward CRAN" and others that are just "things to do eventually".
@alistaire47 I was just reading the running changes coming in R 4.0.0 docs and noticed this under "New Features":
assertError() and assertWarning() (in package tools) can now check for specific error or warning classes via the new optional second argument classes (which is not back compatible with previous use of an unnamed second argument).
Interesting! tryCatch
can already catch classes:
tryCatch(stop(errorCondition('message', class = 'error_class')), error_class = print)
#> <error_class: message>
though not for repeated conditions, which require withCallingHandlers
and some work with restarts. But this seems more like testthat::expect_error
? Not sure if I totally understand what problem it's solving.
The real problem is that devs don't class conditions in the first place. I don't honestly care if anyone ever uses this package if it encourages devs to use already-available tools to set up better classes and restarts. Including r-core, tbh.
Last month I started rror as a hackathon project. In short, it's a wrapper of base R condition (error, warning, message, etc) handling utilities to make them more accessible and comprehensible to package developers and users than the somewhat lacking documentation at
?conditions
. It makes it really simple to raise and catch classed conditions, so if developers want an equivalent of Python'sValueError
,AssertionError
, etc, they can create one, and users can catch specific conditions by class, ignoring others.The goal of this issue is to get
rror
ready for CRAN, as as a package meant to be used primarily as a dependency, it's not much use until its there. Accomplishing this divides into two high-level tasks, in my view:except
the right interface for catching conditions? Should it be renamed or changed into an infix function or something?raise_error(class = "input_error", message = "your input for x is wonky")
. This looks a lot likerlang::abort()
, for better or worse. Making conditions R6 objects with araise()
method is also possible, if people really like R6, though it would add it as a dependency.Help and input on any/all of the above are welcome. If you'd like to learn about
tryCatch()
andwithCallingHandlers()
? What's a restart?) oryou may find an interesting task here!