Skip to content

Support macro ensure_or_internal_err to clean up repeated sanity checks #15492

Closed

Description

@2010YOUY01

Is your feature request related to a problem or challenge?

When implementing complex logic, it's common to include assertions as sanity checks to catch potential errors.
The Rust assert!(...) macro will panic if the condition is false, but in most cases, we want to avoid panicking (which would crash the application). Instead, we prefer to return an internal error to indicate a potential bug. For example:

if self.mode == PartitionMode::Partitioned && left_partitions != right_partitions
{
return internal_err!(
"Invalid HashJoinExec, partition count mismatch {left_partitions}!={right_partitions},\
consider using RepartitionExec"
);
}

Describe the solution you'd like

Implement a macro to throw an internal error when assertion failed

ensure_or_internal_err!(
    !(self.mode == PartitionMode::Partitioned && left_partitions != right_partitions),
    "Invalid HashJoinExec, partition count mismatch {left_partitions}!={right_partitions},\ 
                  consider using RepartitionExec"
);

Perhaps we can create another forbid_or_internal_err for false assertions to make it more clear 🤔

I think this approach only cleaned things up a little, but this check-and-internal-err pattern is very common (used hundreds of times inside the current datafusion source), so I think this chore task is worth the effort.

Describe alternatives you've considered

No response

Additional context

No response

Activity

  1. changed the title [-]Support macro `ensore_or_internal_err` to clean up repeated sanity checks[/-] [+]Support macro `ensure_or_internal_err` to clean up repeated sanity checks[/+] on Mar 30, 2025
  2. alan910127 commented on Mar 30, 2025

    @alan910127
    Contributor

    take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions