viirya commented on code in PR #7115:
URL: https://github.com/apache/arrow-datafusion/pull/7115#discussion_r1281133286


##########
datafusion/common/src/error.rs:
##########
@@ -411,6 +399,56 @@ impl DataFusionError {
     }
 }
 
+/// Unwrap an `Option` if possible. Otherwise return an 
`DataFusionError::Internal`.
+/// In normal usage of DataFusion the unwrap should always succeed.
+///
+/// Example: `let values = unwrap_or_internal_err!(values)`
+#[macro_export]
+macro_rules! unwrap_or_internal_err {
+    ($Value: ident) => {
+        $Value.ok_or_else(|| {
+            DataFusionError::Internal(format!(
+                "{} should not be None",
+                stringify!($Value)
+            ))
+        })?
+    };
+}
+
+#[macro_export]
+macro_rules! with_dollar_sign {
+    ($($body:tt)*) => {
+        macro_rules! __with_dollar_sign { $($body)* }
+        __with_dollar_sign!($);
+    }
+}
+
+/// Add a macros for concise  DataFusionError::* errors declaration
+/// supports placeholders the same way as `format!`
+/// Examples:
+///     plan_err!("Error")
+///     plan_err!("Error {}", val)
+///     plan_err!("Error {:?}", val)
+///     plan_err!("Error {val}")
+///     plan_err!("Error {val:?}")
+macro_rules! make_error {
+    ($NAME:ident, $ERR:ident) => {
+        with_dollar_sign! {
+            ($d:tt) => {
+                #[macro_export]
+                macro_rules! $NAME {
+                    ($d($d args:expr),*) => {
+                        Err(DataFusionError::$ERR(format!($d($d 
args),*).into()))
+                    }
+                }
+            }
+        }
+    };
+}
+
+// DataFusionError::Plan
+make_error!(plan_err, Plan);

Review Comment:
   ```suggestion
   // Exposes a macro to create `DataFusionError::Plan`
   make_error!(plan_err, Plan);
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to