diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-05-07 14:32:29 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-05-07 14:32:29 -0400 |
commit | c50db52da00f4e544a6b3a19ee5b0f54e8503914 (patch) | |
tree | f0557888a6bd3afe9915ce51f6eeb9da3e9a15ba /cmd2/exceptions.py | |
parent | d4653e6fccf0bc15d04075110769c11befb22819 (diff) | |
download | cmd2-git-c50db52da00f4e544a6b3a19ee5b0f54e8503914.tar.gz |
Added SkipPostcommandHooks exception and made Cmd2ArgparseError inherit from it.
Both exception classes have been added to the public API.
Diffstat (limited to 'cmd2/exceptions.py')
-rw-r--r-- | cmd2/exceptions.py | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/cmd2/exceptions.py b/cmd2/exceptions.py index 635192e1..d0a922db 100644 --- a/cmd2/exceptions.py +++ b/cmd2/exceptions.py @@ -1,16 +1,33 @@ # coding=utf-8 -"""Custom exceptions for cmd2. These are NOT part of the public API and are intended for internal use only.""" +"""Custom exceptions for cmd2""" -class Cmd2ArgparseError(Exception): +############################################################################################################ +# The following exceptions are part of the public API +############################################################################################################ + +class SkipPostcommandHooks(Exception): """ - Custom exception class for when a command has an error parsing its arguments. - This can be raised by argparse decorators or the command functions themselves. - The main use of this exception is to tell cmd2 not to run Postcommand hooks. + Custom exception class for when a command has a failure bad enough to skip post command + hooks, but not bad enough to print the exception to the user. """ pass +class Cmd2ArgparseError(SkipPostcommandHooks): + """ + A ``SkipPostcommandHooks`` exception for when a command fails parsing its arguments. + This is raised by argparse decorators but can also be raised by command functions. + If a command function still needs to run post command hooks when parsing fails, + just return instead of raising an exception. + """ + pass + + +############################################################################################################ +# The following exceptions are NOT part of the public API and are intended for internal use only. +############################################################################################################ + class Cmd2ShlexError(Exception): """Raised when shlex fails to parse a command line string in StatementParser""" pass |