alamb commented on code in PR #13664:
URL: https://github.com/apache/datafusion/pull/13664#discussion_r1922380453


##########
datafusion/common/src/error.rs:
##########
@@ -481,8 +488,56 @@ impl DataFusionError {
                 Cow::Owned(format!("{desc}\ncaused by\n{}", *err))
             }
             DataFusionError::Substrait(ref desc) => 
Cow::Owned(desc.to_string()),
+            DataFusionError::Diagnostic(_, ref err) => 
Cow::Owned(err.to_string()),
         }
     }
+
+    /// Wraps the error with contextual information intended for end users
+    pub fn with_diagnostic(self, diagnostic: Diagnostic) -> Self {
+        Self::Diagnostic(diagnostic, Box::new(self))
+    }
+
+    /// Wraps the error with contextual information intended for end users.
+    /// Takes a function that inspects the error and returns the diagnostic to
+    /// wrap it with.
+    pub fn with_diagnostic_fn<F: FnOnce(&DataFusionError) -> Diagnostic>(
+        self,
+        f: F,
+    ) -> Self {
+        let diagnostic = f(&self);
+        self.with_diagnostic(diagnostic)
+    }
+
+    pub fn get_diagnostics(&self) -> impl Iterator<Item = &Diagnostic> + '_ {

Review Comment:
   Minor -- I think a more consistent API would be to call this
   
   ```suggestion
       pub fn diagnostics(&self) -> impl Iterator<Item = &Diagnostic> + '_ {
   ```



-- 
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

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

Reply via email to