Skip to content

Commit

Permalink
chore: return PyResult
Browse files Browse the repository at this point in the history
  • Loading branch information
mesejo committed Oct 6, 2024
1 parent 1d457f8 commit 0724e9a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use object_store::azure::{MicrosoftAzure, MicrosoftAzureBuilder};
use object_store::gcp::{GoogleCloudStorage, GoogleCloudStorageBuilder};
use object_store::http::{HttpBuilder, HttpStore};
use object_store::local::LocalFileSystem;
use pyo3::exceptions::PyValueError;
use url::Url;

#[derive(FromPyObject)]
Expand Down Expand Up @@ -232,19 +233,19 @@ pub struct PyHttpContext {
#[pymethods]
impl PyHttpContext {
#[new]
fn new(url: String) -> Self {
fn new(url: String) -> PyResult<Self> {
let store = match Url::parse(url.as_str()) {
Ok(url) => HttpBuilder::new()
.with_url(url.origin().ascii_serialization())
.build()
.unwrap(),
Err(_) => HttpBuilder::new().build().unwrap(),
};
.build(),
Err(_) => HttpBuilder::new().build(),
}
.map_err(|e| PyValueError::new_err(format!("Error: {:?}", e.to_string())))?;

Self {
Ok(Self {
url,
store: Arc::new(store),
}
})
}
}

Expand Down

0 comments on commit 0724e9a

Please sign in to comment.