@@ -81,7 +81,7 @@ async def info(self, path, session):
81
81
node = unixfsv1 .PBNode .loads (resdata )
82
82
data = unixfsv1 .Data .loads (node .Data )
83
83
if data .Type == unixfsv1 .DataType .Raw :
84
- raise ValueError ( f"The path ' { path } ' is only a subsection of a file" )
84
+ raise FileNotFoundError ( path ) # this is not a file, it's only a part of it
85
85
elif data .Type == unixfsv1 .DataType .Directory :
86
86
return {
87
87
"name" : path ,
@@ -109,14 +109,12 @@ async def info(self, path, session):
109
109
elif data .Type == unixfsv1 .DataType .HAMTShard :
110
110
raise NotImplementedError (f"The path '{ path } ' contains a HAMTSharded directory, this is currently not implemented" )
111
111
else :
112
- raise ValueError ( f"The path ' { path } ' is neiter an IPFS UNIXFSv1 object" )
112
+ raise FileNotFoundError ( path ) # it exists, but is not a UNIXFSv1 object, so it's not a file
113
113
114
114
async def cat (self , path , session ):
115
115
res = await self .get (path , session )
116
116
async with res :
117
117
self ._raise_not_found_for_status (res , path )
118
- if res .status != 200 :
119
- raise FileNotFoundError (path )
120
118
return await res .read ()
121
119
122
120
async def ls (self , path , session , detail = False ):
@@ -129,7 +127,7 @@ async def ls(self, path, session, detail=False):
129
127
data = unixfsv1 .Data .loads (node .Data )
130
128
if data .Type != unixfsv1 .DataType .Directory :
131
129
# TODO: we might need support for HAMTShard here (for large directories)
132
- raise ValueError ( f"The path ' { path } ' is not a directory" )
130
+ raise NotADirectoryError ( path )
133
131
134
132
if detail :
135
133
return await asyncio .gather (* (
@@ -142,9 +140,9 @@ def _raise_not_found_for_status(self, response, url):
142
140
"""
143
141
Raises FileNotFoundError for 404s, otherwise uses raise_for_status.
144
142
"""
145
- if response .status == 404 :
143
+ if response .status == 404 : # returned for known missing files
146
144
raise FileNotFoundError (url )
147
- elif response .status == 400 :
145
+ elif response .status == 400 : # return for invalid requests, so it's also certainly not there
148
146
raise FileNotFoundError (url )
149
147
response .raise_for_status ()
150
148
@@ -301,7 +299,7 @@ async def _info(self, path, **kwargs):
301
299
302
300
def open (self , path , mode = "rb" , block_size = None , cache_options = None , ** kwargs ):
303
301
if mode != "rb" :
304
- raise NotImplementedError
302
+ raise NotImplementedError ( "opening modes other than read binary are not implemented" )
305
303
data = self .cat_file (path ) # load whole chunk into memory
306
304
return io .BytesIO (data )
307
305
0 commit comments