Skip to content

Report unparseable code as an ERROR instead of halting - #270

Merged
LiNk-NY merged 1 commit into
develfrom
parse-error-reporting
Dec 2, 2026
Merged

LiNk-NY merged 1 commit into
develfrom
parse-error-reporting

Conversation

@LiNk-NY

@LiNk-NY LiNk-NY commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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):

* Checking package installation calls in R code...
Error in parse(outfile, keep.source = TRUE) :
  /tmp/RtmpzHWyvq/file37a51c8e3d31/parseFile.tmp:21:0: unexpected end of input
Calls: <Anonymous> ... BiocCheckSource -> parseFiles -> parseFile -> parse
Execution halted

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.
  • Other callers of parseFile() (vignette and R-code symbol checks) skip a file that can't be parsed instead of stopping BiocCheck.

After (rexposome):

* Checking that R, vignette, and example code parses...
✖ ERROR: Unable to parse R code; checks that rely on parsing will skip these files
  Found in files:
    • man/loadExposome_plain.Rd: loadExposome_plain.Rd:21:0: unexpected end of input (line numbers refer to the extracted examples)

After this step, BiocCheck runs to the end and prints its summary.

Checks

  • Added a regression test in inst/tinytest/test_BiocCheck.R. test_BiocCheck.R passes 146 of 146 on R-devel with Bioc 3.25.
  • R CMD build and R CMD check on R-devel with Bioc 3.25: build OK; check Status: 1 NOTE, from existing code (unused commonmark/xml2 Imports and a tools::: call), not from this change.
  • Updated NEWS and the vignette.

Assisted by Claude Opus 5.5.

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>
@LiNk-NY
LiNk-NY requested a review from lshep December 2, 2026 16:44
@LiNk-NY
LiNk-NY merged commit 075274a into devel Dec 2, 2026
@LiNk-NY
LiNk-NY deleted the parse-error-reporting branch December 2, 2026 16:47
Comment thread R/parseFiles.R
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@claude

claude Bot commented Dec 2, 2026

Copy link
Copy Markdown

Issues, in order of importance:

  1. .parseError() builds its empty sentinel with getParseData(parse(text="")). If that returns NULL, the attr<- call errors and BiocCheck halts again. Use an explicit zero-row data.frame with the parse-data columns.
  2. The PR says the other parseFile() callers skip unparseable files, but checkVignettes.R:440 and findSymbols.R:174 are unchanged. They rely on the sentinel being safe, and nothing tests that.
  3. The test covers only the Rd path. It doesn't cover .R files, vignettes, or BiocCheckSource completing. The parsedCode assertion is weak, because it passes whenever the file is dropped for any reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant