diff --git a/crates/polars-error/Cargo.toml b/crates/polars-error/Cargo.toml index 1f4fb3a9a393f..6c1136a357b0c 100644 --- a/crates/polars-error/Cargo.toml +++ b/crates/polars-error/Cargo.toml @@ -11,4 +11,5 @@ description = "Error definitions for the Polars DataFrame library" [dependencies] arrow.workspace = true regex = { version = "1.6", optional = true } +object_store = { version = "0.6.0", default-features = false, optional = true } thiserror.workspace = true diff --git a/crates/polars-error/src/lib.rs b/crates/polars-error/src/lib.rs index 57cc9446427cf..614216b0de32b 100644 --- a/crates/polars-error/src/lib.rs +++ b/crates/polars-error/src/lib.rs @@ -79,6 +79,18 @@ impl From for PolarsError { } } +#[cfg(feature = "object_store")] +impl From for PolarsError { + fn from(err: object_store::Error) -> Self { + PolarsError::Io( + std::io::Error::new( + std::io::ErrorKind::Other, + format!("object store error {err:?}"), + ) + ) + } +} + pub type PolarsResult = Result; pub use arrow::error::Error as ArrowError; diff --git a/crates/polars-io/Cargo.toml b/crates/polars-io/Cargo.toml index 39dff11f15a5a..204da7a40c624 100644 --- a/crates/polars-io/Cargo.toml +++ b/crates/polars-io/Cargo.toml @@ -50,7 +50,7 @@ fmt = ["polars-core/fmt"] lazy = [] parquet = ["polars-core/parquet", "arrow/io_parquet", "arrow/io_parquet_compression", "memmap"] async = ["async-trait", "futures", "tokio", "tokio-util", "arrow/io_ipc_write_async", "polars-error/regex"] -cloud = ["object_store", "async", "polars-core/async", "url"] +cloud = ["object_store", "async", "polars-core/async", "polars-error/object_store", "url"] aws = ["object_store/aws", "cloud", "polars-core/aws"] azure = ["object_store/azure", "cloud", "polars-core/azure"] gcp = ["object_store/gcp", "cloud", "polars-core/gcp"] diff --git a/crates/polars-io/src/cloud/adaptors.rs b/crates/polars-io/src/cloud/adaptors.rs index 983b98212b94a..358233515f33c 100644 --- a/crates/polars-io/src/cloud/adaptors.rs +++ b/crates/polars-io/src/cloud/adaptors.rs @@ -169,10 +169,7 @@ impl CloudWriter { let build_result = runtime.block_on(async { Self::build_writer(&object_store, &path).await }); match build_result { - Err(error) => Err(PolarsError::Io(std::io::Error::new( - std::io::ErrorKind::Other, - format!("object store error {error:?}"), - ))), + Err(error) => Err(PolarsError::from(error)), Ok((multipart_id, writer)) => Ok(CloudWriter { object_store, path,