Skip to content

Add error handling plumbing - #86

Merged
t-kalinowski merged 6 commits into
mainfrom
error-handling
Jan 25, 2026
Merged

Add error handling plumbing#86
t-kalinowski merged 6 commits into
mainfrom
error-handling

Conversation

@t-kalinowski

@t-kalinowski t-kalinowski commented Jan 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • add error buffer plumbing in generated Fortran/C bridges (quickr_err_msg + quickr_set_error_msg) and raise Rf_error() when set
  • translate stop() to the Fortran error setter and propagate early returns across closure calls and sapply() loops
  • surface LAPACK failures in solve(), qr.solve(), chol(), chol2inv() via quickr errors
  • tighten Fortran line continuation handling for long error messages

Motivation

Generated code had no structured way to signal errors back to R, and LAPACK failures could be silent. This adds a minimal error channel so quickr code can raise meaningful errors and callers see them immediately, including inside closures and OpenMP loops.

New API examples

quick(function(x) {
  declare(type(x = double(1)))
  if (x < 0) stop("x must be nonnegative")
  x + 1
})

@codecov

codecov Bot commented Jan 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.02632% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.79%. Comparing base (f6654f4) to head (16bcb7a).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
R/parallel.R 84.21% 3 Missing ⚠️
R/error-handling.R 97.53% 2 Missing ⚠️
R/subroutine.R 96.87% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
+ Coverage   92.42%   92.79%   +0.37%     
==========================================
  Files          26       27       +1     
  Lines        4606     4888     +282     
==========================================
+ Hits         4257     4536     +279     
- Misses        349      352       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6459cc1ed5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread R/error-handling.R Outdated
Comment on lines +105 to +107
check_quickr_error_message_continuable(msg)
msg_literal <- fortran_string_literal(msg)
c(glue("call {quickr_error_setter_name()}({msg_literal})"), "return")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid unconditional return in generated error lines

The helper always emits a bare return after setting the error message. If a user calls stop() (or triggers the Lapack error helpers that reuse this) inside a parallel() loop, the generated code places that return inside a !$omp parallel do region, which OpenMP forbids as a branch out of a parallel region and typically fails to compile. Consider suppressing the return when OpenMP is active and rely on !$omp cancel parallel plus the post-loop error check, or emit a loop-local cycle instead.

Useful? React with 👍 / 👎.

@t-kalinowski

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 14eba24768

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread R/r2f-closures.R Outdated
Comment on lines +882 to +885
error_check_inner <- if (is.null(parallel)) {
quickr_error_return_if_set(scope)
} else {
""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Cancel OpenMP sapply loops on error

When parallel is set, error_check_inner is deliberately empty, so the OpenMP sapply loop never checks quickr_err_msg inside the do region. Because compile_sapply_assignment() never calls enter_openmp_scope(), a stop() in the closure only calls quickr_set_error_msg and returns, and the parallel loop continues to run until completion; the error is only surfaced after the loop. This means OpenMP sapply() can keep executing with known-invalid inputs or side effects long after an error is raised, unlike parallel for loops where !$omp cancel do is triggered promptly. Consider inserting a cancellation check inside the loop for the parallel case or marking the OpenMP scope so stop() emits !$omp cancel do.

Useful? React with 👍 / 👎.

- Keep post-loop error checks inside enclosing OpenMP region
@t-kalinowski

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@t-kalinowski
t-kalinowski merged commit fa7ada1 into main Jan 25, 2026
6 checks passed
@t-kalinowski
t-kalinowski deleted the error-handling branch February 10, 2026 22:06
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