Repository navigation
Re-raise R callback errors by value, not via std::exception_ptr (#3, part 1/2) - #4
Merged
Merged
Conversation
On CRAN's fedora-clang (libc++) errors from R callbacks in bobyqa(), newuoa() and steihaug() surfaced as 'c++ exception (unknown reason)' after std::rethrow_exception. Store the error (unwind token, interrupt or message) by value and throw a fresh exception instead (#3).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4 +/- ##
==========================================
+ Coverage 91.97% 92.00% +0.03%
==========================================
Files 25 26 +1
Lines 3899 3914 +15
==========================================
+ Hits 3586 3601 +15
Misses 313 313 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The INTERRUPT and NONE cases of rethrow() cannot be reached from tests (Rcpp delivers R interrupts as LongjumpException, and callers rethrow only after failed()), which dropped codecov/project on #4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 1 of 2 for #3 (CRAN r-devel-linux-x86_64-fedora-clang test failures).
Problem
On CRAN's fedora-clang (clang + libc++), three tests failed with
c++ exception (unknown reason):test-minqa.R:122,test-steihaug.R:55,test-steihaug.R:114. All three go through the same path: the R callbacks inbobyqa()/newuoa()/steihaug()captured the error withstd::current_exception()and re-raised it after the solver unwound viastd::rethrow_exception(). On that toolchain the rethrown object no longer matched Rcpp'scatchclauses (not evenstd::exception), so it fell intocatch (...).Fix
New
src/r_callback_error.h(RCallbackError) stores the error by value: the Rcpp unwind token (held in anRObject, so it stays protected), an interrupt flag, or thewhat()message. Once the solver has returned, it throws a freshRcpp::LongjumpException/InterruptedException/Rcpp::exception. The original R condition still reaches the caller unchanged through the unwind token.Tests now also check that a custom condition class survives (
expect_error(..., class = "myErr")) fornewuoa,bobyqa,steihaug(fn) andsteihaug(hessvec).Version bumped to 0.2.1 with a NEWS entry.
Verification
devtools::test(): 293 pass (gcc), and the same with a clang build.exception_ptrpath that all three failures share.Next in stack: #5 (OpenMP thread throttling).
🤖 Generated with Claude Code