r-lib / covr

Test coverage reports for R
https://covr.r-lib.org
Other
336 stars 117 forks source link

Applying exclusions raise error due to missing srcref lines #579

Closed dgkf closed 1 week ago

dgkf commented 1 month ago

Identified this odd bug when trying to run covr against diffobj. It's unclear to me why this is popping up for this package.

library(covr)  # using main @c0c88f1
package_coverage("./diffobj")

Coverage tallying finishes successfully, but when applying exclusions will produce the error:

Error in seq.default(df[i, "first_line"], df[i, "last_line"]) :
  'from' must be a finite number
> traceback()
9: stop("'from' must be a finite number")
8: seq.default(df[i, "first_line"], df[i, "last_line"])
7: seq(df[i, "first_line"], df[i, "last_line"])
6: seq(df[i, "first_line"], df[i, "last_line"]) %in% excl[[file]] at exclusions.R#90
5: FUN(X[[i]], ...)
4: vapply(X, FUN, ..., FUN.VALUE = logical(1)) at utils.R#346
3: vlapply(seq_len(NROW(df)), function(i) {
       file <- df[i, "full_name"]
       which_exclusion <- match(file, names(excl))
       !is.na(which_exclusion) && (identical(excl[[which_exclusion]],
           Inf) || all(seq(df[i, "first_line"], df[i, "last_line"]) %in%
           excl[[file]]))
   }) at exclusions.R#85
2: exclude(coverage, line_exclusions = line_exclusions, function_exclusions = function_exclusions,
       path = root) at covr.R#544
1: covr::package_coverage("diffobj"

There's a single trace in the coverage trace data frame with a NA first_line (among other columns), and this can also be see in the pre-transformed coverage object. When debugging the coverage traces before applying exclusions, one trace contains:

$`capt.R:NA:NA:NA:NA:NA:NA:NA:NA`
$`capt.R:NA:NA:NA:NA:NA:NA:NA:NA`$value
[1] 100

$`capt.R:NA:NA:NA:NA:NA:NA:NA:NA`$srcref
<srcref: file "diffobj/R/capt.R" chars NA:NA to NA:NA>

$`capt.R:NA:NA:NA:NA:NA:NA:NA:NA`$functions
[1] "capt_chr"
kyleam commented 4 weeks ago

@dgkf Are you running R 4.4?

I've been troubleshooting what looks to be the same failure for diffobj as well as for a few other packages (data.table, mrgsolve, and nanotime). I hit into these when running the checks for https://mpn.metworx.com packages under R 4.4 rather of than R 4.3.

Based on bisecting with an R source build, I'm pretty confident that this is an interaction with R's revision 84538: 990fe3d8a1 (getParseData() - for first-file objects, 2023-06-14). That was part of the R 4.4.0 release.

Here are some links associated with that commit:

[ +cc @krlmlr ]

dgkf commented 3 weeks ago

@kyleam Thanks for sharing! Yeah, I was testing against 4.4.1 specifically.

I've had limited bandwidth to pursue this bug further, but since filing I've successfully reproduced old covr results on older R versions indicating that this is likely an artifact of a base R change. You definitely seem to be on the right track here.

kyleam commented 3 weeks ago

Yeah, I was testing against 4.4.1 specifically.

Thanks for confirming.

It looks like @MichaelChirico reported the same failure in gh-576.

And there's the related gh-567, where @mcol pointed to the same R 4.4.0 change as the culprit (revision 84538, 990fe3d8a1).