mirror of
https://github.com/beetbox/beets.git
synced 2025-12-24 09:33:46 +01:00
used un-meta-class constructor to reduce verbosity of exception classdefs
--HG-- extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%40103
This commit is contained in:
parent
b34d2308fd
commit
cf4773d64f
1 changed files with 12 additions and 19 deletions
|
|
@ -59,13 +59,19 @@ class BPDError(Exception):
|
|||
to the given command.
|
||||
"""
|
||||
return ErrorResponse(self.code, cmd.name, self.message)
|
||||
|
||||
class ArgumentTypeError(object):
|
||||
"""An error resulting from trying to cast an input argument.
|
||||
|
||||
def make_bpd_error(self, s_code, s_message):
|
||||
"""Create a BPDError subclass for a static code and message.
|
||||
"""
|
||||
code = ERROR_ARG
|
||||
message = 'invalid type for argument'
|
||||
def __init__(self): pass
|
||||
class NewBPDError(BPDError):
|
||||
code = s_code
|
||||
message = s_message
|
||||
def __init__(self): pass
|
||||
return NewBPDError
|
||||
|
||||
ArgumentTypeError = make_bpd_error(ERROR_ARG, 'invalid type for argument')
|
||||
ArgumentIndexError = make_bpd_error(ERROR_ARG, 'argument out of range')
|
||||
ArgumentNotFoundError = make_bpd_error(ERROR_NO_EXIST, 'argument not found')
|
||||
|
||||
def cast_arg(t, val):
|
||||
"""Attempts to call t on val, raising a CommandArgumentError
|
||||
|
|
@ -82,19 +88,6 @@ def cast_arg(t, val):
|
|||
except ValueError:
|
||||
raise CommandArgumentError()
|
||||
|
||||
class ArgumentIndexError(object):
|
||||
"""An error resulting from an out-of-range index argument.
|
||||
"""
|
||||
code = ERROR_ARG
|
||||
message = 'argument out of range'
|
||||
def __init__(self): pass
|
||||
|
||||
class ArgumentNotFoundError(object):
|
||||
"""An error for arguments that do not exist."""
|
||||
code = ERROR_NO_EXIST
|
||||
message = 'argument not found'
|
||||
def __init__(self): pass
|
||||
|
||||
class BPDClose(Exception):
|
||||
"""Raised by a command invocation to indicate that the connection
|
||||
should be closed.
|
||||
|
|
|
|||
Loading…
Reference in a new issue