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 5, 2024
1 parent 1d457f8 commit 0907a6e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 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(),
.map_err(|e| PyValueError::new_err(format!("Error: {:?}", e.to_string())))?,
Err(_) => HttpBuilder::new().build().unwrap(),
};

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

Expand Down

0 comments on commit 0907a6e

Please sign in to comment.