@@ -259,13 +259,13 @@ def open(
259259 and self .filesystem .exists (path )
260260 and not self .filesystem .isdir (path )
261261 ):
262- raise OSError (errno .ENOTDIR , "path is not a directory" , path )
262+ self . filesystem . raise_os_error (errno .ENOTDIR , path )
263263
264264 has_follow_flag = (
265265 hasattr (os , "O_NOFOLLOW" ) and flags & os .O_NOFOLLOW == os .O_NOFOLLOW
266266 )
267267 if has_follow_flag and self .filesystem .islink (path ):
268- raise OSError (errno .ELOOP , "path is a symlink" , path )
268+ self . filesystem . raise_os_error (errno .ELOOP , path )
269269
270270 has_tmpfile_flag = (
271271 hasattr (os , "O_TMPFILE" ) and flags & os .O_TMPFILE == os .O_TMPFILE
@@ -392,7 +392,7 @@ def lseek(self, fd: int, pos: int, whence: int):
392392 if isinstance (file_handle , FakeFileWrapper ):
393393 file_handle .seek (pos , whence )
394394 else :
395- raise OSError (errno .EBADF , "Bad file descriptor for fseek" )
395+ self . filesystem . raise_os_error (errno .EBADF )
396396
397397 def pipe (self ) -> Tuple [int , int ]:
398398 read_fd , write_fd = os .pipe ()
@@ -453,13 +453,13 @@ def chdir(self, path: AnyStr) -> None:
453453 path = self .filesystem .resolve_path (path , allow_fd = True )
454454 except OSError as exc :
455455 if self .filesystem .is_macos and exc .errno == errno .EBADF :
456- raise OSError (errno .ENOTDIR , "Not a directory: " + str (path ))
456+ self . filesystem . raise_os_error (errno .ENOTDIR , str (path ))
457457 elif (
458458 self .filesystem .is_windows_fs
459459 and exc .errno == errno .ENOENT
460460 and path == ""
461461 ):
462- raise OSError (errno .EINVAL , "Invalid argument: + str(path)" )
462+ self . filesystem . raise_os_error (errno .EINVAL , str (path ))
463463 raise
464464 try :
465465 self .filesystem .confirmdir (path )
@@ -528,7 +528,7 @@ def getxattr(
528528 attribute = attribute .decode (sys .getfilesystemencoding ())
529529 file_obj = self .filesystem .resolve (path , follow_symlinks , allow_fd = True )
530530 if attribute not in file_obj .xattr :
531- raise OSError (errno .ENODATA , "No data available" , path )
531+ self . filesystem . raise_os_error (errno .ENODATA , path )
532532 return file_obj .xattr .get (attribute )
533533
534534 def listxattr (
@@ -1026,7 +1026,7 @@ def ftruncate(self, fd: int, length: int) -> None:
10261026 if isinstance (file_object , FakeFileWrapper ):
10271027 file_object .size = length
10281028 else :
1029- raise OSError (errno .EBADF , "Invalid file descriptor" )
1029+ self . filesystem . raise_os_error (errno .EBADF )
10301030
10311031 def access (
10321032 self ,
0 commit comments