diff options
author | rfkelly0 <rfkelly0@67cdc799-7952-0410-af00-57a81ceafa0f> | 2009-05-05 06:03:50 +0000 |
---|---|---|
committer | rfkelly0 <rfkelly0@67cdc799-7952-0410-af00-57a81ceafa0f> | 2009-05-05 06:03:50 +0000 |
commit | 8c151c786fdd3cbbdde252ec25ac9bbc1e2fd0e0 (patch) | |
tree | 7c10b30cfe1304568ca3c505dbc4c5ff418b9c3d /fs | |
parent | 2c6521ce00108a712eec79e6c579c5252648b885 (diff) | |
download | pyfilesystem-git-8c151c786fdd3cbbdde252ec25ac9bbc1e2fd0e0.tar.gz |
first cut at a new Exception heirarchy
Diffstat (limited to 'fs')
-rw-r--r-- | fs/errors.py | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/fs/errors.py b/fs/errors.py new file mode 100644 index 0000000..35b038c --- /dev/null +++ b/fs/errors.py @@ -0,0 +1,104 @@ +""" + + fs.errors: error class definitions for FS + +""" + +class FSError(Exception): + """Base exception class for the FS module.""" + + default_message = "Unspecified error" + + def __init__(self,msg=None,details=None): + if msg is None: + msg = self.default_message + self.msg = msg + self.details = details + + def __str__(self): + keys = dict((k,str(v)) for k,v in self.__dict__.iteritems()) + return "FSError: " + (self.msg % keys) + + def __unicode__(self): + return unicode(str(self)) + + +class PathError(FSError): + """Exception for errors to do with a path string.""" + + default_message = "Path is invalid: %(path)s" + + def __init__(self,path,**kwds): + self.path = path + super(ResourceError,self).__init__(**kwds) + + +class OperationFailedError(FSError): + """Base exception class for errors associated with a specific operation.""" + + default_message = "Unable to %(opname)s: unspecified error" + + def __init__(self,opname,path=None,**kwds): + self.opname = opname + self.path = path + super(OperationFailedError,self).__init__(**kwds) + + +class UnsupportedError(OperationFailedError): + """Exception raised for operations that are not supported by the FS.""" + default_message = "Unable to %(opname)s: not supported by this filesystem" + + +class ResourceError(FSError): + """Base exception class for error associated with a specific resource.""" + + default_message = "Unspecified resource error: %(path)s" + + def __init__(self,path,**kwds): + self.path = path + super(ResourceError,self).__init__(**kwds) + + +class NoSysPathError(ResourceError): + """Exception raised when there is no syspath for a given path.""" + default_message = "No mapping to OS filesystem: %(path)s" + + +class ResourceNotFoundError(ResourceError): + """Exception raised when a required resource is not found.""" + default_message = "Resource not found: %(path)s" + + +class DirectoryNotFoundError(ResourceNotFoundError): + """Exception raised when a required directory is not found.""" + default_message = "Directory not found: %(path)s" + + +class FileNotFoundError(ResourceNotFoundError): + """Exception raised when a required file is not found.""" + default_message = "File not found: %(path)s" + + +class ResourceInvalidError(ResourceError): + """Exception raised when a required file is not found.""" + default_message = "Resource is invalid: %(path)s" + + +class DestinationExistsError(ResourceError): + """Exception raised when a target destination already exists.""" + default_message = "Destination exists: %(path)s" + + +class DirectoryNotEmptyError(ResourceError): + """Exception raised when a directory to be removed is not empty.""" + default_message = "Directory is not empty: %(path)s" + + +class ParentDirectoryMissingError(ResourceError): + """Exception raised when a parent directory is missing.""" + default_message = "Parent directory is missing: %(path)s" + + +class ResourceLockedError(ResourceError): + """Exception raised when a resource can't be used because it is locked.""" + default_message = "Resource is locked: %(path)s" |