Skip to content

Commit 3ac9bb2

Browse files
authored
Rename ObstoreError to BaseError (#200)
* Rename ObstoreError to BaseError * Fix tests
1 parent 1bf47c6 commit 3ac9bb2

File tree

9 files changed

+43
-41
lines changed

9 files changed

+43
-41
lines changed

obstore/python/obstore/exceptions/__init__.pyi

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@
22
# pylance isn't able to find that. So this is an exceptions module with only
33
# `__init__.pyi` to work around pylance's bug.
44

5-
class ObstoreError(Exception):
5+
class BaseError(Exception):
66
"""The base exception class"""
77

8-
class GenericError(ObstoreError):
8+
class GenericError(BaseError):
99
"""A fallback error type when no variant matches."""
1010

11-
class NotFoundError(ObstoreError):
11+
class NotFoundError(BaseError):
1212
"""Error when the object is not found at given location."""
1313

14-
class InvalidPathError(ObstoreError):
14+
class InvalidPathError(BaseError):
1515
"""Error for invalid path."""
1616

17-
class JoinError(ObstoreError):
17+
class JoinError(BaseError):
1818
"""Error when `tokio::spawn` failed."""
1919

20-
class NotSupportedError(ObstoreError):
20+
class NotSupportedError(BaseError):
2121
"""Error when the attempted operation is not supported."""
2222

23-
class AlreadyExistsError(ObstoreError):
23+
class AlreadyExistsError(BaseError):
2424
"""Error when the object already exists."""
2525

26-
class PreconditionError(ObstoreError):
26+
class PreconditionError(BaseError):
2727
"""Error when the required conditions failed for the operation."""
2828

29-
class NotModifiedError(ObstoreError):
29+
class NotModifiedError(BaseError):
3030
"""Error when the object at the location isn't modified."""
3131

32-
class PermissionDeniedError(ObstoreError):
32+
class PermissionDeniedError(BaseError):
3333
"""
3434
Error when the used credentials don't have enough permission
3535
to perform the requested operation
3636
"""
3737

38-
class UnauthenticatedError(ObstoreError):
38+
class UnauthenticatedError(BaseError):
3939
"""Error when the used credentials lack valid authentication."""
4040

41-
class UnknownConfigurationKeyError(ObstoreError):
41+
class UnknownConfigurationKeyError(BaseError):
4242
"""Error when a configuration key is invalid for the store used."""

pyo3-object_store/src/api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn register_exceptions_module(
7878

7979
let child_module = PyModule::new(parent_module.py(), "exceptions")?;
8080

81-
child_module.add("ObstoreError", py.get_type::<ObstoreError>())?;
81+
child_module.add("BaseError", py.get_type::<BaseError>())?;
8282
child_module.add("GenericError", py.get_type::<GenericError>())?;
8383
child_module.add("NotFoundError", py.get_type::<NotFoundError>())?;
8484
child_module.add("InvalidPathError", py.get_type::<InvalidPathError>())?;

pyo3-object_store/src/aws.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use pyo3::{intern, IntoPyObjectExt};
1111

1212
use crate::client::PyClientOptions;
1313
use crate::config::PyConfigValue;
14-
use crate::error::{ObstoreError, PyObjectStoreError, PyObjectStoreResult};
14+
use crate::error::{GenericError, PyObjectStoreError, PyObjectStoreResult};
1515
use crate::path::PyPath;
1616
use crate::prefix::MaybePrefixedStore;
1717
use crate::retry::PyRetryConfig;
@@ -313,7 +313,7 @@ impl PyAmazonS3Config {
313313
for (k, v) in other.0.into_iter() {
314314
let old_value = self.0.insert(k.clone(), v);
315315
if old_value.is_some() {
316-
return Err(ObstoreError::new_err(format!(
316+
return Err(GenericError::new_err(format!(
317317
"Duplicate key {} between config and kwargs",
318318
k.0.as_ref()
319319
))

pyo3-object_store/src/azure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use pyo3::{intern, IntoPyObjectExt};
1111

1212
use crate::client::PyClientOptions;
1313
use crate::config::PyConfigValue;
14-
use crate::error::{ObstoreError, PyObjectStoreError, PyObjectStoreResult};
14+
use crate::error::{GenericError, PyObjectStoreError, PyObjectStoreResult};
1515
use crate::path::PyPath;
1616
use crate::retry::PyRetryConfig;
1717
use crate::{MaybePrefixedStore, PyUrl};
@@ -238,7 +238,7 @@ impl PyAzureConfig {
238238
for (k, v) in other.0.into_iter() {
239239
let old_value = self.0.insert(k.clone(), v);
240240
if old_value.is_some() {
241-
return Err(ObstoreError::new_err(format!(
241+
return Err(GenericError::new_err(format!(
242242
"Duplicate key {} between config and kwargs",
243243
k.0.as_ref()
244244
))

pyo3-object_store/src/error.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ use pyo3::{create_exception, DowncastError};
77
use thiserror::Error;
88

99
// Base exception
10+
// Note that this is named `BaseError` instead of `ObstoreError` to not leak the name "obstore" to
11+
// other Rust-Python libraries using pyo3-object_store.
1012
create_exception!(
1113
pyo3_object_store,
12-
ObstoreError,
14+
BaseError,
1315
pyo3::exceptions::PyException,
1416
"The base Python-facing exception from which all other errors subclass."
1517
);
@@ -18,67 +20,67 @@ create_exception!(
1820
create_exception!(
1921
pyo3_object_store,
2022
GenericError,
21-
ObstoreError,
23+
BaseError,
2224
"A Python-facing exception wrapping [object_store::Error::Generic]."
2325
);
2426
create_exception!(
2527
pyo3_object_store,
2628
NotFoundError,
27-
ObstoreError,
29+
BaseError,
2830
"A Python-facing exception wrapping [object_store::Error::NotFound]."
2931
);
3032
create_exception!(
3133
pyo3_object_store,
3234
InvalidPathError,
33-
ObstoreError,
35+
BaseError,
3436
"A Python-facing exception wrapping [object_store::Error::InvalidPath]."
3537
);
3638
create_exception!(
3739
pyo3_object_store,
3840
JoinError,
39-
ObstoreError,
41+
BaseError,
4042
"A Python-facing exception wrapping [object_store::Error::JoinError]."
4143
);
4244
create_exception!(
4345
pyo3_object_store,
4446
NotSupportedError,
45-
ObstoreError,
47+
BaseError,
4648
"A Python-facing exception wrapping [object_store::Error::NotSupported]."
4749
);
4850
create_exception!(
4951
pyo3_object_store,
5052
AlreadyExistsError,
51-
ObstoreError,
53+
BaseError,
5254
"A Python-facing exception wrapping [object_store::Error::AlreadyExists]."
5355
);
5456
create_exception!(
5557
pyo3_object_store,
5658
PreconditionError,
57-
ObstoreError,
59+
BaseError,
5860
"A Python-facing exception wrapping [object_store::Error::Precondition]."
5961
);
6062
create_exception!(
6163
pyo3_object_store,
6264
NotModifiedError,
63-
ObstoreError,
65+
BaseError,
6466
"A Python-facing exception wrapping [object_store::Error::NotModified]."
6567
);
6668
create_exception!(
6769
pyo3_object_store,
6870
PermissionDeniedError,
69-
ObstoreError,
71+
BaseError,
7072
"A Python-facing exception wrapping [object_store::Error::PermissionDenied]."
7173
);
7274
create_exception!(
7375
pyo3_object_store,
7476
UnauthenticatedError,
75-
ObstoreError,
77+
BaseError,
7678
"A Python-facing exception wrapping [object_store::Error::Unauthenticated]."
7779
);
7880
create_exception!(
7981
pyo3_object_store,
8082
UnknownConfigurationKeyError,
81-
ObstoreError,
83+
BaseError,
8284
"A Python-facing exception wrapping [object_store::Error::UnknownConfigurationKey]."
8385
);
8486

pyo3-object_store/src/gcp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use pyo3::{intern, IntoPyObjectExt};
1111

1212
use crate::client::PyClientOptions;
1313
use crate::config::PyConfigValue;
14-
use crate::error::{ObstoreError, PyObjectStoreError, PyObjectStoreResult};
14+
use crate::error::{GenericError, PyObjectStoreError, PyObjectStoreResult};
1515
use crate::path::PyPath;
1616
use crate::retry::PyRetryConfig;
1717
use crate::{MaybePrefixedStore, PyUrl};
@@ -236,7 +236,7 @@ impl PyGoogleConfig {
236236
for (k, v) in other.0.into_iter() {
237237
let old_value = self.0.insert(k.clone(), v);
238238
if old_value.is_some() {
239-
return Err(ObstoreError::new_err(format!(
239+
return Err(GenericError::new_err(format!(
240240
"Duplicate key {} between config and kwargs",
241241
k.0.as_ref()
242242
))

pyo3-object_store/src/simple.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use pyo3::prelude::*;
66
use pyo3::types::{PyDict, PyType};
77
use pyo3::{intern, IntoPyObjectExt};
88

9-
use crate::error::ObstoreError;
9+
use crate::error::GenericError;
1010
use crate::retry::PyRetryConfig;
1111
use crate::url::PyUrl;
1212
use crate::{
@@ -100,7 +100,7 @@ pub fn from_url(
100100
Ok(store.into_pyobject(py)?.into_py_any(py)?)
101101
}
102102
scheme => {
103-
return Err(ObstoreError::new_err(format!("Unknown URL scheme {:?}", scheme,)).into());
103+
return Err(GenericError::new_err(format!("Unknown URL scheme {:?}", scheme,)).into());
104104
}
105105
}
106106
}
@@ -111,7 +111,7 @@ fn raise_if_config_passed(
111111
scheme: &str,
112112
) -> PyObjectStoreResult<()> {
113113
if config.is_some() || kwargs.is_some() {
114-
return Err(ObstoreError::new_err(format!(
114+
return Err(GenericError::new_err(format!(
115115
"Cannot pass config or keyword parameters for scheme {:?}",
116116
scheme,
117117
))

tests/store/test_from_url.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from obstore.exceptions import ObstoreError, UnknownConfigurationKeyError
5+
from obstore.exceptions import BaseError, UnknownConfigurationKeyError
66
from obstore.store import from_url
77

88

@@ -16,7 +16,7 @@ def test_memory():
1616
url = "memory:///"
1717
_store = from_url(url)
1818

19-
with pytest.raises(ObstoreError):
19+
with pytest.raises(BaseError):
2020
from_url(url, aws_access_key_id="test")
2121

2222

@@ -51,5 +51,5 @@ def test_http():
5151
url = "https://mydomain/path"
5252
from_url(url)
5353

54-
with pytest.raises(ObstoreError):
54+
with pytest.raises(BaseError):
5555
from_url(url, aws_bucket="test")

tests/store/test_s3.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
import obstore as obs
7-
from obstore.exceptions import ObstoreError
7+
from obstore.exceptions import BaseError
88
from obstore.store import S3Store, from_url
99

1010

@@ -27,14 +27,14 @@ def test_construct_store_boolean_config():
2727

2828

2929
def test_error_overlapping_config_kwargs():
30-
with pytest.raises(ObstoreError, match="Duplicate key"):
30+
with pytest.raises(BaseError, match="Duplicate key"):
3131
S3Store("bucket", config={"skip_signature": True}, skip_signature=True)
3232

3333
# Also raises for variations of the same parameter
34-
with pytest.raises(ObstoreError, match="Duplicate key"):
34+
with pytest.raises(BaseError, match="Duplicate key"):
3535
S3Store("bucket", config={"aws_skip_signature": True}, skip_signature=True)
3636

37-
with pytest.raises(ObstoreError, match="Duplicate key"):
37+
with pytest.raises(BaseError, match="Duplicate key"):
3838
S3Store("bucket", config={"AWS_SKIP_SIGNATURE": True}, skip_signature=True)
3939

4040

0 commit comments

Comments
 (0)