mirror of
https://github.com/ejwa/gitinspector.git
synced 2025-01-03 11:22:15 +01:00
Fixed a long-standing bug with exceptions not being able to handle unicode.
This was fixed by storing the exception string manually inside each exception class. The error message is now stored in exception.msg instead of relying on __str__(). It seems the normal behavior (by printing exceptions directly) is broken in Python 2. It *does* work in Python 3, but this is because it always handles everything as unicode.
This commit is contained in:
parent
5c9335088a
commit
b28d86d1f2
3 changed files with 12 additions and 4 deletions
|
@ -32,7 +32,11 @@ DEFAULT_FORMAT = __available_formats__[2]
|
|||
__selected_format__ = DEFAULT_FORMAT
|
||||
|
||||
class InvalidFormatError(Exception):
|
||||
pass
|
||||
def __init__(self, msg):
|
||||
self.msg = msg
|
||||
|
||||
def msg():
|
||||
return self.msg
|
||||
|
||||
def select(format):
|
||||
global __selected_format__
|
||||
|
|
|
@ -178,8 +178,8 @@ def main():
|
|||
elif o in("-x", "--exclude"):
|
||||
filtering.add(a)
|
||||
|
||||
except (format.InvalidFormatError, optval.InvalidOptionArgument, getopt.error) as msg:
|
||||
print(sys.argv[0], "\b:", msg)
|
||||
except (format.InvalidFormatError, optval.InvalidOptionArgument, getopt.error) as exception:
|
||||
print(sys.argv[0], "\b:", exception.msg)
|
||||
print(_("Try `{0} --help' for more information.").format(sys.argv[0]))
|
||||
sys.exit(2)
|
||||
|
||||
|
|
|
@ -20,7 +20,11 @@ from __future__ import unicode_literals
|
|||
import getopt
|
||||
|
||||
class InvalidOptionArgument(Exception):
|
||||
pass
|
||||
def __init__(self, msg):
|
||||
self.msg = msg
|
||||
|
||||
def msg():
|
||||
return self.msg
|
||||
|
||||
def __find_arg_in_options__(arg, options):
|
||||
for opt in options:
|
||||
|
|
Loading…
Reference in a new issue