From 0f09cef7c497ea826df526d2d3a5b018279c4d2f Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 10 Jul 2009 14:11:23 -0400 Subject: 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? ;) --- libbe/cmdutil.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libbe/cmdutil.py') 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(" Date: Fri, 10 Jul 2009 17:58:49 -0400 Subject: seems to work ;) --- libbe/cmdutil.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libbe/cmdutil.py') diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py index 7414e46..ada0423 100644 --- a/libbe/cmdutil.py +++ b/libbe/cmdutil.py @@ -56,9 +56,11 @@ def iter_commands(): def get_command(command_name): """Retrieves the module for a user command - >>> get_command("asdf") - Traceback (most recent call last): - UnknownCommand: Unknown command asdf + >>> try: + ... get_command("asdf") + ... except UnknownCommand, e: + ... print e + Unknown command asdf >>> repr(get_command("list")).startswith("