Skip to content

Commit 0bf830e

Browse files
authored
Raise informative error if region detection fails (#558)
* Raise informative error if region detection fails * Fix test
1 parent eaf9c0f commit 0bf830e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

virtualizarr/manifests/store.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ def _find_bucket_region(bucket_name: str) -> str:
131131
import requests
132132

133133
resp = requests.head(f"https://{bucket_name}.s3.amazonaws.com")
134-
return resp.headers["x-amz-bucket-region"]
134+
region = resp.headers.get("x-amz-bucket-region")
135+
if not region:
136+
raise ValueError(
137+
f"Unable to automatically determine region for bucket {bucket_name}"
138+
)
139+
return region
135140

136141

137142
def default_object_store(filepath: str) -> ObjectStore:

virtualizarr/tests/test_manifests/test_store.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ def test_default_object_store_local(tmpdir):
161161
assert isinstance(store, LocalStore)
162162

163163

164+
@requires_obstore
165+
def test_default_region_raises():
166+
file = "s3://cworthy/oae-efficiency-atlas/data/experiments/000/01/alk-forcing.000-1999-01.pop.h.0347-01.nc"
167+
with pytest.raises(
168+
ValueError, match="Unable to automatically determine region for bucket*"
169+
):
170+
default_object_store(file)
171+
172+
164173
@requires_obstore
165174
class TestManifestStore:
166175
def test_manifest_store_properties(self, local_store):

0 commit comments

Comments
 (0)