Repository navigation
Report unparseable code as an ERROR instead of halting - #270
Conversation
parseFile() now catches parse errors in R files, tangled vignette code, and Rd examples, and returns empty parse data with the message attached. parseFiles() reports these once as a BiocCheck ERROR that names the source file rather than the temporary parseFile.tmp, and runs as its own step before the install-calls check. Other callers of parseFile() skip unparseable files instead of stopping BiocCheck. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| else if (!identical(infile, outfile)) | ||
| msg <- paste0(msg, " (line numbers refer to the tangled R code)") | ||
| pd <- getParseData(parse(text = "", keep.source = TRUE)) | ||
| attr(pd, "parse_error") <- msg |
There was a problem hiding this comment.
getParseData(parse(text = "", keep.source = TRUE)) is fragile as the "empty" sentinel. For an expression with no tokens, getParseData() can return NULL, and attr(NULL, "parse_error") <- msg then fails with "attempt to set an attribute on NULL". That would put a new halting error inside the handler meant to prevent one. Build the data frame explicitly instead, or return a zero-row data.frame with the columns that callers index (line1, col1, token, text, parent, id, ...). Also, callers such as findSymbolsInVignettes and .VigCodeChunkNo index those columns, so the sentinel needs them.
| parsedCode <- BiocCheck:::parseFiles(.bioctest) | ||
| expect_false(any(grepl("broken.Rd", names(parsedCode), fixed = TRUE))) | ||
| checkCounter("Unparseable Rd example didn't cause error!") | ||
| unlink(temp_dir, recursive = TRUE) |
There was a problem hiding this comment.
Coverage is thin. (1) expect_false(any(grepl("broken.Rd", names(parsedCode)))) also passes if the file were dropped for any reason, so assert the error message text or file name too (e.g. via .BiocCheck$get("error") or similar). (2) Only an Rd file is tested. The .R path (where outfile == infile) and the vignette tangle path (the "tangled R code" suffix) are untested. (3) Nothing tests the claim in the PR description that checkVigSessionInfo, findSymbolsInVignettes and the other parseFile() callers skip the broken file, or that BiocCheckSource runs to completion. Please add tests for these.
|
Issues, in order of importance:
|
BiocCheck stops with an unhelpful error when any R file, vignette chunk, or Rd example can't be parsed, as happened with rexposome (isglobal-brge/rexposome#10):
The message points to a temporary file instead of the source (here,
man/loadExposome_plain.Rd), and no later checks run.Changes
parseFile()catches parse errors and returns empty parse data with the message attached. The message keeps only the first line of the parser's error and names the real file instead of the temp file. For Rd and vignette files it notes that line numbers refer to the extracted code.parseFiles()reports all parse failures once, as an ERROR, and leaves those files out of the parsed code.parseFiles()now runs as its own step, "Checking that R, vignette, and example code parses...", before the install-calls check.parseFile()(vignette and R-code symbol checks) skip a file that can't be parsed instead of stopping BiocCheck.After (rexposome):
After this step, BiocCheck runs to the end and prints its summary.
Checks
inst/tinytest/test_BiocCheck.R.test_BiocCheck.Rpasses 146 of 146 on R-devel with Bioc 3.25.R CMD buildandR CMD checkon R-devel with Bioc 3.25: build OK; checkStatus: 1 NOTE, from existing code (unusedcommonmark/xml2Imports and atools:::call), not from this change.Assisted by Claude Opus 5.5.