Skip to content

Conversation

@jrwishart
Copy link
Contributor

@jrwishart jrwishart commented Oct 11, 2025

Preserve UserError class when re-throwing exceptions in data merging/stacking operations, ensuring proper error handling and user-facing error messages and preventing stop conditions and generating false positives for unexpected errors in bugdup.

@jrwishart jrwishart requested a review from Copilot October 11, 2025 22:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates exception handling in data merging/stacking operations to preserve UserError classes when re-throwing exceptions. The changes ensure that user-facing errors maintain their proper error type while preventing false positives in error monitoring systems.

  • Refactored the createExceptionHandler function to detect and preserve UserError types
  • Added import for StopForUserError from the flipU package
  • Updated version number to reflect these changes

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
R/mergingandstackingutilities.R Refactored exception handler to preserve UserError types and use appropriate error functions
DESCRIPTION Incremented version number from 1.8.9 to 1.8.10

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +68 to +74
condition.fun <- function(...) {
if (warn) {
warning(..., call. = FALSE)
} else if (inherits(e, "UserError")) {
StopForUserError(...)
} else {
stop(..., call. = FALSE)
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

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

The condition.fun closure captures the exception e from the outer scope, but this creates a dependency on the outer variable that may not be the intended behavior. When condition.fun is called with different messages, it still checks inherits(e, "UserError") based on the original exception, which may not match the current context where condition.fun is being invoked.

Suggested change
condition.fun <- function(...) {
if (warn) {
warning(..., call. = FALSE)
} else if (inherits(e, "UserError")) {
StopForUserError(...)
} else {
stop(..., call. = FALSE)
condition.fun <- function(msg) {
if (warn) {
warning(msg, call. = FALSE)
} else {
if (inherits(e, "UserError")) {
StopForUserError(msg)
} else {
stop(msg, call. = FALSE)
}

Copilot uses AI. Check for mistakes.
Comment on lines +68 to +76
condition.fun <- function(...) {
if (warn) {
warning(..., call. = FALSE)
} else if (inherits(e, "UserError")) {
StopForUserError(...)
} else {
stop(..., call. = FALSE)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the actual change. Some minor differences below since the call. argument is already specified here.

@jrwishart jrwishart requested a review from JustinCCYap October 12, 2025 21:33
Copy link
Contributor

@JustinCCYap JustinCCYap left a comment

Choose a reason for hiding this comment

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

LGTM

@jrwishart jrwishart merged commit 35dd9d0 into master Oct 12, 2025
2 of 4 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.

3 participants