james-willis commented on code in PR #1144:
URL: https://github.com/apache/sedona-db/pull/1144#discussion_r3866999814


##########
rust/sedona-raster/src/error.rs:
##########
@@ -0,0 +1,192 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! The raster crates' domain error type.
+//!
+//! The raster code used to plumb [`arrow_schema::ArrowError`] everywhere,
+//! which forced a `map_err` at every boundary that produced or consumed a
+//! raster error. [`RasterError`] mirrors `sedona-geometry`'s
+//! `SedonaGeometryError`: a small `thiserror` enum that library accessors
+//! return directly, with `From` bridges so callers use `?` instead of a
+//! hand-written `map_err`.
+//!
+//! The one raster-specific addition over the geometry mirror is the
+//! [`RasterError::Arrow`] variant with `#[from] ArrowError`: raster code
+//! calls Arrow APIs constantly, so `?` over an `ArrowError` needs to resolve
+//! to a `RasterError` without a `map_err`.
+//!
+//! Boundaries:
+//! - `From<ArrowError> for RasterError` — `?` over Arrow calls inside the
+//!   raster library.
+//! - `From<RasterError> for DataFusionError` — `?` at UDF boundaries (the
+//!   raster-functions / raster-gdal crates return `DataFusionError`).
+//! - `From<RasterError> for ArrowError` — the bridge back for signatures
+//!   fixed by Arrow, notably `RecordBatchReader::next`.
+//!
+//! Internal-assertion errors ("this is a SedonaDB bug") are intentionally
+//! *not* a variant here: they stay a boundary concern raised through
+//! `sedona_common::sedona_internal_err!`, which produces a `DataFusionError`
+//! directly — same as `sedona-geometry`, which has no internal variant.
+
+use arrow_schema::ArrowError;
+use datafusion_common::DataFusionError;
+use thiserror::Error;
+
+/// Error type for the raster crates.
+///
+/// Mirrors `sedona_geometry::error::SedonaGeometryError`. Construct
+/// [`RasterError::Invalid`] for a bad-input/precondition failure and
+/// [`RasterError::External`] to carry an arbitrary source error; Arrow
+/// errors convert automatically via `?`.
+#[derive(Error, Debug)]
+pub enum RasterError {
+    /// Invalid input or a violated precondition, described by the message.
+    #[error("{0}")]
+    Invalid(String),
+    /// An Arrow error encountered while building or reading raster arrays.
+    #[error(transparent)]
+    Arrow(#[from] ArrowError),
+    /// Any other source error, boxed.
+    #[error(transparent)]
+    External(Box<dyn std::error::Error + Send + Sync>),
+    /// A raster error with no more specific classification.
+    #[error("Unknown raster error")]
+    Unknown,
+}
+
+impl From<RasterError> for DataFusionError {
+    fn from(value: RasterError) -> Self {
+        match value {
+            // Keep Arrow errors typed so DataFusion renders them as Arrow
+            // errors rather than an opaque external error.
+            RasterError::Arrow(e) => DataFusionError::ArrowError(Box::new(e), 
None),

Review Comment:
   no not intentional. good idea, will add



##########
rust/sedona-raster/src/error.rs:
##########
@@ -0,0 +1,192 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! The raster crates' domain error type.
+//!
+//! The raster code used to plumb [`arrow_schema::ArrowError`] everywhere,
+//! which forced a `map_err` at every boundary that produced or consumed a
+//! raster error. [`RasterError`] mirrors `sedona-geometry`'s
+//! `SedonaGeometryError`: a small `thiserror` enum that library accessors
+//! return directly, with `From` bridges so callers use `?` instead of a
+//! hand-written `map_err`.
+//!
+//! The one raster-specific addition over the geometry mirror is the
+//! [`RasterError::Arrow`] variant with `#[from] ArrowError`: raster code
+//! calls Arrow APIs constantly, so `?` over an `ArrowError` needs to resolve
+//! to a `RasterError` without a `map_err`.
+//!
+//! Boundaries:
+//! - `From<ArrowError> for RasterError` — `?` over Arrow calls inside the
+//!   raster library.
+//! - `From<RasterError> for DataFusionError` — `?` at UDF boundaries (the
+//!   raster-functions / raster-gdal crates return `DataFusionError`).
+//! - `From<RasterError> for ArrowError` — the bridge back for signatures
+//!   fixed by Arrow, notably `RecordBatchReader::next`.
+//!
+//! Internal-assertion errors ("this is a SedonaDB bug") are intentionally
+//! *not* a variant here: they stay a boundary concern raised through
+//! `sedona_common::sedona_internal_err!`, which produces a `DataFusionError`
+//! directly — same as `sedona-geometry`, which has no internal variant.
+
+use arrow_schema::ArrowError;
+use datafusion_common::DataFusionError;
+use thiserror::Error;
+
+/// Error type for the raster crates.
+///
+/// Mirrors `sedona_geometry::error::SedonaGeometryError`. Construct
+/// [`RasterError::Invalid`] for a bad-input/precondition failure and
+/// [`RasterError::External`] to carry an arbitrary source error; Arrow
+/// errors convert automatically via `?`.
+#[derive(Error, Debug)]
+pub enum RasterError {
+    /// Invalid input or a violated precondition, described by the message.
+    #[error("{0}")]
+    Invalid(String),
+    /// An Arrow error encountered while building or reading raster arrays.
+    #[error(transparent)]
+    Arrow(#[from] ArrowError),
+    /// Any other source error, boxed.
+    #[error(transparent)]
+    External(Box<dyn std::error::Error + Send + Sync>),
+    /// A raster error with no more specific classification.
+    #[error("Unknown raster error")]
+    Unknown,
+}
+
+impl From<RasterError> for DataFusionError {
+    fn from(value: RasterError) -> Self {
+        match value {
+            // Keep Arrow errors typed so DataFusion renders them as Arrow
+            // errors rather than an opaque external error.
+            RasterError::Arrow(e) => DataFusionError::ArrowError(Box::new(e), 
None),
+            // `Execution` (not `Internal`/`External`) matches the existing
+            // `exec_datafusion_err!` sites this replaces: a user-facing
+            // execution error without the "this is a DataFusion bug" framing.
+            RasterError::Invalid(msg) => DataFusionError::Execution(msg),
+            RasterError::External(e) => DataFusionError::External(e),
+            RasterError::Unknown => DataFusionError::Execution("Unknown raster 
error".to_string()),
+        }
+    }
+}
+
+impl From<RasterError> for ArrowError {
+    fn from(value: RasterError) -> Self {
+        match value {
+            RasterError::Arrow(e) => e,
+            other => ArrowError::ExternalError(Box::new(other)),

Review Comment:
   done



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