mgirlich/tibblify

Improve error message for error in `transform`

Opened this issue · 2 comments

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

  • the issue was when applying transform
  • spec path to the tib() (or at least the name) where the issue was
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

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 r-lib/cpp11#277

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.