Skip to content

Clearer error when include*() helpers are given a missing file#448

Merged
schloerke merged 8 commits into
rstudio:mainfrom
samuelbharti:samuelbharti/include-missing-file-errors
May 27, 2026
Merged

Clearer error when include*() helpers are given a missing file#448
schloerke merged 8 commits into
rstudio:mainfrom
samuelbharti:samuelbharti/include-missing-file-errors

Conversation

@samuelbharti

@samuelbharti samuelbharti commented May 27, 2026

Copy link
Copy Markdown
Contributor

Fixes rstudio/shiny#1757

Summary

  • includeCSS(), includeHTML(), includeText(), includeMarkdown(), and includeScript() previously surfaced the generic cannot open the connection message from readLines() when given a non-existent path.
  • This PR adds an up-front file.exists() check via a new internal helper check_include_path(), which raises a structured rlang::abort() naming the missing file.
  • NEWS.md updated.

Test plan

  • devtools::test() passes
  • Manually verify each helper raises the new error when given a missing path
  • Manually verify each helper still works for an existing file

Check file.exists(path) up front and raise a structured rlang::abort()
naming the missing file, instead of letting readLines() surface the
generic "cannot open the connection" message.
Factor the file.exists() check into check_include_path() and apply it
to includeHTML(), includeText(), includeMarkdown(), and includeScript()
so they all raise a clear error naming the missing path, matching the
behavior just added to includeCSS().
@CLAassistant

CLAassistant commented May 27, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Verify includeCSS(), includeHTML(), includeText(), includeMarkdown(),
and includeScript() each raise a clear error naming both the file type
and the missing path when given a non-existent file.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread R/tags.R Outdated
Comment thread R/tags.R Outdated
Comment thread tests/testthat/test-tags.r
samuelbharti and others added 4 commits May 27, 2026 15:10
Move skip_if_not_installed("markdown") into its own test_that() so the
skip sits at the top of the test, and remove the second test that only
re-checked includeCSS().

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pass call = rlang::caller_env() into rlang::abort() so the error
header reads "Error in includeCSS():" (or the relevant helper)
rather than "Error in check_include_path():", making the source
of the problem easier for users to find.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Guard check_include_path() against two edge cases that previously
surfaced confusing errors:

- NULL, character(0), multi-element vectors, "", and NA_character_
  inputs now raise a clear "path must be a single non-empty string"
  message instead of "argument is of length zero" from file.exists().
- A directory at `path` now raises the same "does not exist" error
  instead of the cryptic message from readLines().

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@schloerke

schloerke commented May 27, 2026

Copy link
Copy Markdown
Collaborator

Failing checks are unrelated to PR.

Waiting for fixes before merging

@schloerke schloerke merged commit a8e70ed into rstudio:main May 27, 2026
17 checks passed
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.

Vague Error if CSS File Missing

3 participants