mgirlich / tibblify

Rectangle Nested Lists
https://mgirlich.github.io/tibblify/
GNU General Public License v3.0
67 stars 2 forks source link

Improve error message for error in `transform` #152

Open mgirlich opened 2 years ago

mgirlich commented 2 years ago

The error message is currently not very helpful. It should mention

library(tibblify)

tibblify(
  list(
    list(x = 1),
    list(x = 2)
  ),
  tspec_df(tib_chr("x", ptype_inner = integer(), transform = ~ log(-.x)))
)
#> Warning in log(-.x): NaNs produced
#> Error in `tibblify()`:
#> ! Problem while tibblifying `x[[2]]`
#> Caused by error:
#> ! Can't convert <double> to <character>.

Created on 2022-07-27 by the reprex package (v2.0.1)

Probably this needs R_tryEvalSilent(), see Errors and Evaluation

mgirlich commented 2 years ago

This is a bit more complicated than expected. At least there is only little documentation how to catch R errors and pass them along to a custom error handler. Also see https://github.com/r-lib/cpp11/issues/277

mgirlich commented 2 years ago

Idea: change Path to a Context class that carries more information: path to element of x, path to field spec, where the error was thrown e.g. when applying transform or when casting to ptype or ptype_inner.