@@ -576,7 +576,9 @@ async def _info(self, path, refresh=False, **kwargs):
576
576
) as cc :
577
577
properties = await cc .get_container_properties ()
578
578
except ResourceNotFoundError as exc :
579
- raise FileNotFoundError from exc
579
+ raise FileNotFoundError (
580
+ errno .ENOENT , "No such container" , container
581
+ ) from exc
580
582
info = (await self ._details ([properties ]))[0 ]
581
583
# Make result consistent with _ls_containers()
582
584
if not info .get ("metadata" ):
@@ -1384,15 +1386,15 @@ async def _pipe(self, *args, batch_size=None, max_concurrency=None, **kwargs):
1384
1386
async def _cat_file (
1385
1387
self , path , start = None , end = None , max_concurrency = None , ** kwargs
1386
1388
):
1387
- path = self ._strip_protocol (path )
1389
+ stripped_path = self ._strip_protocol (path )
1388
1390
if end is not None :
1389
1391
start = start or 0 # download_blob requires start if length is provided.
1390
1392
length = end - start
1391
1393
else :
1392
1394
length = None
1393
- container_name , path , version_id = self .split_path (path )
1395
+ container_name , blob , version_id = self .split_path (stripped_path )
1394
1396
async with self .service_client .get_blob_client (
1395
- container = container_name , blob = path
1397
+ container = container_name , blob = blob
1396
1398
) as bc :
1397
1399
try :
1398
1400
stream = await bc .download_blob (
@@ -1403,10 +1405,14 @@ async def _cat_file(
1403
1405
** self ._timeout_kwargs ,
1404
1406
)
1405
1407
except ResourceNotFoundError as e :
1406
- raise FileNotFoundError from e
1408
+ raise FileNotFoundError (
1409
+ errno .ENOENT , os .strerror (errno .ENOENT ), path
1410
+ ) from e
1407
1411
except HttpResponseError as e :
1408
1412
if version_id is not None :
1409
- raise FileNotFoundError from e
1413
+ raise FileNotFoundError (
1414
+ errno .ENOENT , os .strerror (errno .ENOENT ), path
1415
+ ) from e
1410
1416
raise
1411
1417
result = await stream .readall ()
1412
1418
return result
@@ -1586,7 +1592,9 @@ async def _put_file(
1586
1592
raise FileExistsError ("File already exists!" )
1587
1593
except ResourceNotFoundError :
1588
1594
if not await self ._exists (container_name ):
1589
- raise FileNotFoundError ("Container does not exist." )
1595
+ raise FileNotFoundError (
1596
+ errno .ENOENT , "No such container" , container_name
1597
+ )
1590
1598
await self ._put_file (lpath , rpath , delimiter , overwrite )
1591
1599
self .invalidate_cache ()
1592
1600
@@ -1600,16 +1608,16 @@ async def _put(self, *args, batch_size=None, max_concurrency=None, **kwargs):
1600
1608
1601
1609
async def _cp_file (self , path1 , path2 , ** kwargs ):
1602
1610
"""Copy the file at path1 to path2"""
1603
- container1 , path1 , version_id = self .split_path (path1 , delimiter = "/" )
1604
- container2 , path2 , _ = self .split_path (path2 , delimiter = "/" )
1611
+ container1 , blob1 , version_id = self .split_path (path1 , delimiter = "/" )
1612
+ container2 , blob2 , _ = self .split_path (path2 , delimiter = "/" )
1605
1613
1606
1614
cc1 = self .service_client .get_container_client (container1 )
1607
- blobclient1 = cc1 .get_blob_client (blob = path1 )
1615
+ blobclient1 = cc1 .get_blob_client (blob = blob1 )
1608
1616
if container1 == container2 :
1609
- blobclient2 = cc1 .get_blob_client (blob = path2 )
1617
+ blobclient2 = cc1 .get_blob_client (blob = blob2 )
1610
1618
else :
1611
1619
cc2 = self .service_client .get_container_client (container2 )
1612
- blobclient2 = cc2 .get_blob_client (blob = path2 )
1620
+ blobclient2 = cc2 .get_blob_client (blob = blob2 )
1613
1621
url = (
1614
1622
blobclient1 .url
1615
1623
if version_id is None
@@ -1618,7 +1626,9 @@ async def _cp_file(self, path1, path2, **kwargs):
1618
1626
try :
1619
1627
await blobclient2 .start_copy_from_url (url )
1620
1628
except ResourceNotFoundError as e :
1621
- raise FileNotFoundError from e
1629
+ raise FileNotFoundError (
1630
+ errno .ENOENT , os .strerror (errno .ENOENT ), path1
1631
+ ) from e
1622
1632
self .invalidate_cache (container1 )
1623
1633
self .invalidate_cache (container2 )
1624
1634
@@ -1661,7 +1671,9 @@ async def _get_file(
1661
1671
with open (lpath , "wb" ) as my_blob :
1662
1672
await stream .readinto (my_blob )
1663
1673
except ResourceNotFoundError as exception :
1664
- raise FileNotFoundError from exception
1674
+ raise FileNotFoundError (
1675
+ errno .ENOENT , os .strerror (errno .ENOENT ), rpath
1676
+ ) from exception
1665
1677
1666
1678
get_file = sync_wrapper (_get_file )
1667
1679
@@ -1682,7 +1694,9 @@ async def _setxattrs(self, rpath, **kwargs):
1682
1694
await bc .set_blob_metadata (metadata = kwargs )
1683
1695
self .invalidate_cache (self ._parent (rpath ))
1684
1696
except Exception as e :
1685
- raise FileNotFoundError (f"File not found for { e } " )
1697
+ raise FileNotFoundError (
1698
+ errno .ENOENT , os .strerror (errno .ENOENT ), rpath
1699
+ ) from e
1686
1700
1687
1701
setxattrs = sync_wrapper (_setxattrs )
1688
1702
0 commit comments