From 187efbd6451130a86aaa2aa44e6d77d627aea540 Mon Sep 17 00:00:00 2001 From: Patrick Vos Date: Sat, 7 Dec 2013 13:20:39 +0100 Subject: [PATCH] Change ex(e) use complete e.args not only first item On errors like IOerror or OSerror e.args[0] is only a number, adding the rest of the tuple makes it more descriptive. + replace tabs with spaces --- sickbeard/exceptions.py | 110 ++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 39 deletions(-) diff --git a/sickbeard/exceptions.py b/sickbeard/exceptions.py index 2e0b0b4f97..9d657fea30 100644 --- a/sickbeard/exceptions.py +++ b/sickbeard/exceptions.py @@ -18,83 +18,115 @@ from sickbeard.encodingKludge import fixStupidEncodings + def ex(e): - """ - Returns a unicode string from the exception text if it exists. - """ - - # sanity check - if not e.args or not e.args[0]: - return "" - - e_message = fixStupidEncodings(e.args[0], True) - - # if fixStupidEncodings doesn't fix it then maybe it's not a string, in which case we'll try printing it anyway - if not e_message: - try: - e_message = str(e.args[0]) - except: - e_message = "" - - return e_message - + """ + Returns a unicode string from the exception text if it exists. + """ + + e_message = u"" + + if not e or not e.args: + return e_message + + for arg in e.args: + + if arg is not None: + if isinstance(arg, (str, unicode)): + fixed_arg = fixStupidEncodings(arg, True) + + else: + try: + fixed_arg = u"error " + fixStupidEncodings(str(arg), True) + + except: + fixed_arg = None + + if fixed_arg: + if not e_message: + e_message = fixed_arg + + else: + e_message = e_message + " : " + fixed_arg + + return e_message + class SickBeardException(Exception): - "Generic SickBeard Exception - should never be thrown, only subclassed" + "Generic SickBeard Exception - should never be thrown, only subclassed" + class ConfigErrorException(SickBeardException): - "Error in the config file" + "Error in the config file" + class LaterException(SickBeardException): - "Something bad happened that I'll make a real exception for later" + "Something bad happened that I'll make a real exception for later" + class NoNFOException(SickBeardException): - "No NFO was found!" + "No NFO was found!" + class NoShowDirException(SickBeardException): - "Unable to find the show's directory" + "Unable to find the show's directory" + class FileNotFoundException(SickBeardException): - "The specified file doesn't exist" + "The specified file doesn't exist" + class MultipleDBEpisodesException(SickBeardException): - "Found multiple episodes in the DB! Must fix DB first" + "Found multiple episodes in the DB! Must fix DB first" + class MultipleDBShowsException(SickBeardException): - "Found multiple shows in the DB! Must fix DB first" + "Found multiple shows in the DB! Must fix DB first" + class MultipleShowObjectsException(SickBeardException): - "Found multiple objects for the same show! Something is very wrong" + "Found multiple objects for the same show! Something is very wrong" + class WrongShowException(SickBeardException): - "The episode doesn't belong to the same show as its parent folder" + "The episode doesn't belong to the same show as its parent folder" + class ShowNotFoundException(SickBeardException): - "The show wasn't found on theTVDB" + "The show wasn't found on theTVDB" + class EpisodeNotFoundException(SickBeardException): - "The episode wasn't found on theTVDB" + "The episode wasn't found on theTVDB" + class NewzbinAPIThrottled(SickBeardException): - "Newzbin has throttled us, deal with it" + "Newzbin has throttled us, deal with it" + class TVRageException(SickBeardException): - "TVRage API did something bad" + "TVRage API did something bad" + class ShowDirNotFoundException(SickBeardException): - "The show dir doesn't exist" + "The show dir doesn't exist" + class AuthException(SickBeardException): - "Your authentication information is incorrect" + "Your authentication information is incorrect" + class EpisodeDeletedException(SickBeardException): - "This episode has been deleted" + "This episode has been deleted" + class CantRefreshException(SickBeardException): - "The show can't be refreshed right now" + "The show can't be refreshed right now" + class CantUpdateException(SickBeardException): - "The show can't be updated right now" + "The show can't be updated right now" + class PostProcessingFailed(SickBeardException): - "Post-processing the episode failed" \ No newline at end of file + "Post-processing the episode failed"