Commit 974e63d7 by rfkelly0

report correct line numbers in various error decorators

parent 34c1d36a
...@@ -159,36 +159,37 @@ def convert_os_errors(func): ...@@ -159,36 +159,37 @@ def convert_os_errors(func):
try: try:
return func(self,*args,**kwds) return func(self,*args,**kwds)
except (OSError,IOError), e: except (OSError,IOError), e:
(exc_type,exc_inst,tb) = sys.exc_info()
path = getattr(e,"filename",None) path = getattr(e,"filename",None)
if path and path[0] == "/" and hasattr(self,"root_path"): if path and path[0] == "/" and hasattr(self,"root_path"):
path = normpath(path) path = normpath(path)
if isprefix(self.root_path,path): if isprefix(self.root_path,path):
path = path[len(self.root_path):] path = path[len(self.root_path):]
if not hasattr(e,"errno") or not e.errno: if not hasattr(e,"errno") or not e.errno:
raise OperationFailedError(opname,details=e) raise OperationFailedError(opname,details=e),None,tb
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
raise ResourceNotFoundError(path,opname=opname,details=e) raise ResourceNotFoundError(path,opname=opname,details=e),None,tb
if e.errno == errno.ENOTEMPTY: if e.errno == errno.ENOTEMPTY:
raise DirectoryNotEmptyError(path,opname=opname,details=e) raise DirectoryNotEmptyError(path,opname=opname,details=e),None,tb
if e.errno == errno.EEXIST: if e.errno == errno.EEXIST:
raise DestinationExistsError(path,opname=opname,details=e) raise DestinationExistsError(path,opname=opname,details=e),None,tb
if e.errno == 183: # some sort of win32 equivalent to EEXIST if e.errno == 183: # some sort of win32 equivalent to EEXIST
raise DestinationExistsError(path,opname=opname,details=e) raise DestinationExistsError(path,opname=opname,details=e),None,tb
if e.errno == errno.ENOTDIR: if e.errno == errno.ENOTDIR:
raise ResourceInvalidError(path,opname=opname,details=e) raise ResourceInvalidError(path,opname=opname,details=e),None,tb
if e.errno == errno.EISDIR: if e.errno == errno.EISDIR:
raise ResourceInvalidError(path,opname=opname,details=e) raise ResourceInvalidError(path,opname=opname,details=e),None,tb
if e.errno == errno.EINVAL: if e.errno == errno.EINVAL:
raise ResourceInvalidError(path,opname=opname,details=e) raise ResourceInvalidError(path,opname=opname,details=e),None,tb
if e.errno == errno.EOPNOTSUPP: if e.errno == errno.EOPNOTSUPP:
raise UnsupportedError(opname,details=e) raise UnsupportedError(opname,details=e),None,tb
if e.errno == errno.ENOSPC: if e.errno == errno.ENOSPC:
raise StorageSpaceError(opname,details=e) raise StorageSpaceError(opname,details=e),None,tb
# Sometimes windows gives some random errors... # Sometimes windows gives some random errors...
if sys.platform == "win32": if sys.platform == "win32":
if e.errno in (13,): if e.errno in (13,):
raise ResourceInvalidError(path,opname=opname,details=e) raise ResourceInvalidError(path,opname=opname,details=e),None,tb
raise OperationFailedError(opname,details=e) raise OperationFailedError(opname,details=e),None,tb
return wrapper return wrapper
...@@ -13,6 +13,7 @@ directory listings. ...@@ -13,6 +13,7 @@ directory listings.
""" """
import sys
from fnmatch import fnmatch from fnmatch import fnmatch
from fs.base import FS, threading, synchronize from fs.base import FS, threading, synchronize
...@@ -24,10 +25,11 @@ def rewrite_errors(func): ...@@ -24,10 +25,11 @@ def rewrite_errors(func):
try: try:
return func(self,*args,**kwds) return func(self,*args,**kwds)
except ResourceError, e: except ResourceError, e:
(exc_type,exc_inst,tb) = sys.exc_info()
try: try:
e.path = self._decode(e.path) e.path = self._decode(e.path)
except (AttributeError, ValueError, TypeError): except (AttributeError, ValueError, TypeError):
raise e raise e, None, tb
raise raise
return wrapper return wrapper
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment