diff options
author | W. Trevor King <wking@drexel.edu> | 2009-07-10 14:11:23 -0400 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-07-10 14:11:23 -0400 |
commit | 0f09cef7c497ea826df526d2d3a5b018279c4d2f (patch) | |
tree | ba198d2d478cc4f65184f9069b74c1a8570cd35a /libbe/cmdutil.py | |
parent | e5c0d5f2f3f7637cad6baca9e33778d0c054195d (diff) | |
download | bugseverywhere-0f09cef7c497ea826df526d2d3a5b018279c4d2f.tar.gz |
Simplified error handling in ./be
Removed superfluous nesting in ./be's error catching. Also replaced
KeyErrors due to unknown commands with the more specific
cmdutil.UnknownCommand, since all sorts of programming errors can
raise KeyErrors.
Untested, since my working tree is a mess at the moment, but what
could go wrong? ;)
Diffstat (limited to 'libbe/cmdutil.py')
-rw-r--r-- | libbe/cmdutil.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py index 0dd8ad0..7414e46 100644 --- a/libbe/cmdutil.py +++ b/libbe/cmdutil.py @@ -32,10 +32,10 @@ class UserError(Exception): def __init__(self, msg): Exception.__init__(self, msg) -class UserErrorWrap(UserError): - def __init__(self, exception): - UserError.__init__(self, str(exception)) - self.exception = exception +class UnknownCommand(UserError): + def __init__(self, cmd): + Exception.__init__(self, "Unknown command '%s'" % cmd) + self.cmd = cmd class UsageError(Exception): pass @@ -58,13 +58,13 @@ def get_command(command_name): >>> get_command("asdf") Traceback (most recent call last): - UserError: Unknown command asdf + UnknownCommand: Unknown command asdf >>> repr(get_command("list")).startswith("<module 'becommands.list' from ") True """ cmd = plugin.get_plugin("becommands", command_name.replace("-", "_")) if cmd is None: - raise UserError("Unknown command %s" % command_name) + raise UnknownCommand(command_name) return cmd |