Skip to content
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

Pass error call through C errors #187

Open
DavisVaughan opened this issue Nov 15, 2022 · 0 comments
Open

Pass error call through C errors #187

DavisVaughan opened this issue Nov 15, 2022 · 0 comments
Labels
feature a feature request or enhancement

Comments

@DavisVaughan
Copy link
Member

Or set some kind of local_slider_error_call() before going to C that the R error callbacks can look to for the error call

We started using snapshot tests a lot more in #186, so any improvements will be easily visible. Here are a few cases where the error call either is set to NULL and doesn't show or we throw a base R error

library(slider)

slide_int(1, ~1.5)
#> Error:
#> ! Can't convert from <double> to <integer> due to loss of precision.
#> • Locations: 1

#> Backtrace:
#>      ▆
#>   1. └─slider::slide_int(1, ~1.5)
#>   2.   └─slider:::slide_vec_direct(...) at slider/R/slide.R:295:2
#>   3.     └─slider:::slide_impl(...) at slider/R/slide.R:250:2
#>   4.       └─slider:::slide_common(...) at slider/R/slide.R:430:2
#>   5.         └─slider (local) `<fn>`() at slider/R/slide-common.R:2:2
#>   6.           └─vctrs:::vec_cast.integer.double(...)
#>   7.             └─vctrs::maybe_lossy_cast(...)
#>   8.               ├─base::withRestarts(...)
#>   9.               │ └─base (local) withOneRestart(expr, restarts[[1L]])
#>  10.               │   └─base (local) doWithOneRestart(return(expr), restart)
#>  11.               └─vctrs:::stop_lossy_cast(...)
#>  12.                 └─vctrs::stop_incompatible_cast(...)
#>  13.                   └─vctrs::stop_incompatible_type(...)
#>  14.                     └─vctrs:::stop_incompatible(...)
#>  15.                       └─vctrs:::stop_vctrs(...)
#>  16.                         └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = vctrs_error_call(call))

slide(1, identity, .before = -1)
#> Error: When `.before` (-1) is negative, it's absolute value (1) cannot be greater than `.after` (0).

slide(1, identity, .before = -1, .after = -1)
#> Error: `.before` (-1) and `.after` (-1) cannot both be negative.

slide(1, identity, .before = "x")
#> Error:
#> ! Can't convert <character> to <integer>.

#> Backtrace:
#>      ▆
#>   1. ├─slider::slide(1, identity, .before = "x")
#>   2. │ └─slider:::slide_impl(...) at slider/R/slide.R:201:2
#>   3. │   └─slider:::slide_common(...) at slider/R/slide.R:430:2
#>   4. └─vctrs (local) `<fn>`() at slider/R/slide-common.R:2:2
#>   5.   └─vctrs::vec_default_cast(...)
#>   6.     ├─base::withRestarts(...)
#>   7.     │ └─base (local) withOneRestart(expr, restarts[[1L]])
#>   8.     │   └─base (local) doWithOneRestart(return(expr), restart)
#>   9.     └─vctrs::stop_incompatible_cast(...)
#>  10.       └─vctrs::stop_incompatible_type(...)
#>  11.         └─vctrs:::stop_incompatible(...)
#>  12.           └─vctrs:::stop_vctrs(...)
#>  13.             └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = vctrs_error_call(call))

Created on 2022-11-15 with reprex v2.0.2.9000

@DavisVaughan DavisVaughan added the feature a feature request or enhancement label Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant