gabotechs commented on code in PR #7:
URL: https://github.com/apache/datafusion-iceberg/pull/7#discussion_r4069510046
##########
crates/datafusion/src/error.rs:
##########
@@ -15,18 +15,106 @@
// specific language governing permissions and limitations
// under the License.
-use anyhow::anyhow;
+use datafusion::error::DataFusionError;
use iceberg::{Error, ErrorKind};
/// Converts a datafusion error into an iceberg error.
-pub fn from_datafusion_error(error: datafusion::error::DataFusionError) ->
Error {
+pub fn from_datafusion_error(error: DataFusionError) -> Error {
+ let fallback_message = error.to_string();
+ let DataFusionError::Context(context, error) = error else {
+ return unexpected_datafusion_error(fallback_message);
+ };
+
+ let Some(kind) = parse_iceberg_error_kind(&context) else {
+ return unexpected_datafusion_error(fallback_message);
+ };
+ let DataFusionError::Execution(message) = error.as_ref() else {
+ return unexpected_datafusion_error(fallback_message);
+ };
+
+ Error::new(kind, strip_error_kind(kind, message))
+}
+
+/// Converts an iceberg error into a datafusion error.
+pub fn to_datafusion_error(error: Error) -> DataFusionError {
+ DataFusionError::Context(
+ format!("IcebergError({})", error.kind()),
+ Box::new(DataFusionError::Execution(error.to_string())),
+ )
+}
Review Comment:
If anyone has better ideas on how to encode iceberg errors into
DataFusionError that's very welcome
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]