Skip to content

Commit 92c20d3

Browse files
authored
fix: clarify error message and docstrings in Blob class method (#1196)
* fix: clarify error message and docstrings * run docs
1 parent a179337 commit 92c20d3

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

google/cloud/storage/blob.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ def from_string(cls, uri, client=None):
394394
blob = Blob.from_string("gs://bucket/object", client=client)
395395
396396
:type uri: str
397-
:param uri: The blob uri pass to get blob object.
397+
:param uri: The blob uri following a gs://bucket/object pattern.
398+
Both a bucket and object name is required to construct a blob object.
398399
399400
:type client: :class:`~google.cloud.storage.client.Client`
400401
:param client:
@@ -408,7 +409,7 @@ def from_string(cls, uri, client=None):
408409

409410
match = _GS_URL_REGEX_PATTERN.match(uri)
410411
if not match:
411-
raise ValueError("URI scheme must be gs")
412+
raise ValueError("URI pattern must be gs://bucket/object")
412413
bucket = Bucket(client, name=match.group("bucket_name"))
413414
return cls(match.group("object_name"), bucket)
414415

tests/unit/test_blob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5840,7 +5840,7 @@ def test_from_string_w_invalid_uri(self):
58405840

58415841
client = self._make_client()
58425842

5843-
with pytest.raises(ValueError, match="URI scheme must be gs"):
5843+
with pytest.raises(ValueError):
58445844
Blob.from_string("http://bucket_name/b", client)
58455845

58465846
def test_from_string_w_domain_name_bucket(self):

tests/unit/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ def test_download_blob_to_file_with_invalid_uri(self):
17501750
client = self._make_one(project=project, credentials=credentials)
17511751
file_obj = io.BytesIO()
17521752

1753-
with pytest.raises(ValueError, match="URI scheme must be gs"):
1753+
with pytest.raises(ValueError):
17541754
client.download_blob_to_file("http://bucket_name/path/to/object", file_obj)
17551755

17561756
def test_download_blob_to_file_w_no_retry(self):

0 commit comments

Comments
 (0)