Skip to content

Commit

Permalink
Standardize conversion of object_store::Error -> PolarsError
Browse files Browse the repository at this point in the history
  • Loading branch information
Qqwy committed Jul 28, 2023
1 parent 46c1cd3 commit 0a24501
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/polars-error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions crates/polars-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ impl From<regex::Error> for PolarsError {
}
}

#[cfg(feature = "object_store")]
impl From<object_store::Error> 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<T> = Result<T, PolarsError>;

pub use arrow::error::Error as ArrowError;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
5 changes: 1 addition & 4 deletions crates/polars-io/src/cloud/adaptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0a24501

Please sign in to comment.