Changeset 1554:406c84da6e3b


Ignore:
Timestamp:
Oct 4, 2014, 8:34:31 AM (7 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Make error handling more robust.

This _should_ also fix ticket #85. There's no guarantee though since I
don't know where the byte string came from so I can't be sure I fixed
the actual problem from the ticket.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ftputil/error.py

    r1483 r1554  
    1818# it's _not_ recommended.
    1919__all__ = [
    20   "FTPError",
    21   "InternalError",
     20 "InternalError",
    2221  "RootDirError",
    2322  "InaccessibleLoginDirError",
     
    4241        super(FTPError, self).__init__(*args)
    4342        if "original_exception" in kwargs:
    44             self.strerror = ftputil.compat.unicode_type(
     43            self.strerror = ftputil.tool.as_unicode(
    4544                              kwargs.pop("original_exception"))
    4645        elif args:
    4746            # If there was no `original_exception` argument, assume
    48             # the first argument is a unicode string.
    49             self.strerror = args[0]
     47            # the first argument is a string. It may be a byte string
     48            # though.
     49            self.strerror = ftputil.tool.as_unicode(args[0])
    5050        else:
    5151            self.strerror = ""
     
    5353            self.errno = int(self.strerror[:3])
    5454        except (TypeError, IndexError, ValueError):
     55            # TODO: List where all these exceptions may come from.
    5556            self.errno = None
    5657        self.file_name = None
     
    128129            return
    129130        if isinstance(exc_value, ftplib.error_temp):
    130             raise TemporaryError(*exc_value.args)
     131            raise TemporaryError(*exc_value.args, original_exception=exc_value)
    131132        elif isinstance(exc_value, ftplib.error_perm):
    132133            # If `exc_value.args[0]` is present, assume it's a byte or
     
    138139                raise CommandNotImplementedError(*exc_value.args)
    139140            else:
    140                 raise PermanentError(*exc_value.args)
     141                raise PermanentError(*exc_value.args,
     142                                     original_exception=exc_value)
    141143        elif isinstance(exc_value, ftplib.all_errors):
    142144            raise FTPOSError(*exc_value.args, original_exception=exc_value)
     
    166168            return
    167169        if isinstance(exc_value, ftplib.all_errors):
    168             raise FTPIOError(*exc_value.args)
     170            raise FTPIOError(*exc_value.args, original_exception=exc_value)
    169171        else:
    170172            raise
Note: See TracChangeset for help on using the changeset viewer.