2010YOUY01 opened a new issue, #15492: URL: https://github.com/apache/datafusion/issues/15492
### 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: https://github.com/apache/datafusion/blob/e2b7919e28c56e618231c4b4489d452ee1ef5a8c/datafusion/physical-plan/src/joins/hash_join.rs#L786-L792 ### Describe the solution you'd like Implement a macro to throw an internal error when assertion failed ```rust 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_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org