Skip to content

build_pkgdown.R: use withCallingHandlers to muffle and collect warnings (#4034) - #4099

Merged
infotroph merged 2 commits into
PecanProject:developfrom
Anurag-M1:fix/pkgdown-warn-muffle-4034
Sep 9, 2026
Merged

infotroph merged 2 commits into
PecanProject:developfrom
Anurag-M1:fix/pkgdown-warn-muffle-4034

Conversation

@Anurag-M1

Copy link
Copy Markdown
Contributor

Description

Refactors build_quietly() in scripts/build_pkgdown.R to collect warnings using withCallingHandlers instead of an exiting tryCatch handler.

Motivation and Context

Closes #4034.

Previously, build_quietly() caught warnings via tryCatch(..., warning = function(w) {...}). Because tryCatch warning handlers are exiting handlers:

  1. Control unwinds to the tryCatch frame before the handler executes, so the muffleWarning restart is no longer in scope (causing tryInvokeRestart("muffleWarning") to be a no-op or error with no 'restart' 'muffleWarning' found).
  2. Returning from the handler abandons build_and_copy() instead of allowing subsequent build steps to finish.

By using withCallingHandlers for the warning branch nested inside tryCatch for error:

  • Warnings are handled in the signalling context, allowing tryInvokeRestart("muffleWarning") to muffle duplicate console printing.
  • build_and_copy() continues executing to completion.
  • Warnings are safely appended to warns as intact condition objects.
  • Downstream warning logging in scripts/build_pkgdown.R safely calls conditionMessage(w) for each warning condition across packages.
  • Reconciled the stale # TODO this branch doesn't ever seem to run comment.

Review Time Estimate

  • When possible

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My change requires a change to the documentation.
  • My name is in the list of CITATION.cff
  • I agree that PEcAn Project may distribute my contribution under any or all of
    • the same license as the existing code,
    • and/or the BSD 3-clause license.
  • I have updated the CHANGELOG.md.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

…gs (PecanProject#4034)

In build_quietly(), replace the exiting tryCatch warning handler with
withCallingHandlers nested inside tryCatch. This runs the warning handler
in the signalling context so that muffleWarning is available and invoked,
preventing build_and_copy() from being abandoned prematurely when non-fatal
warnings are emitted.

Also update downstream warning iteration to extract conditionMessage
safely for each warning condition.
Comment thread CHANGELOG.md Resolved
@infotroph
infotroph added this pull request to the merge queue Sep 9, 2026
Merged via the queue into PecanProject:develop with commit 1950b89 Sep 9, 2026
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build_pkgdown.R - build_quietly() can't muffle and resume warnings when using tryCatch

2 participants