diff options
author | Doug Hellmann <doug.hellmann@gmail.com> | 2012-04-22 15:14:02 -0700 |
---|---|---|
committer | Doug Hellmann <doug.hellmann@gmail.com> | 2012-04-22 15:14:02 -0700 |
commit | 276e8a4694575d15bf6c722f758343d4ca635495 (patch) | |
tree | 8c71e20c939648bb87af8212cfa866268882556d /demoapp | |
parent | c842a1bfce909240fa40d7e7a79b1f31bfa464a8 (diff) | |
download | cliff-276e8a4694575d15bf6c722f758343d4ca635495.tar.gz |
add some error handling to App
Diffstat (limited to 'demoapp')
-rw-r--r-- | demoapp/cliffdemo/main.py | 8 | ||||
-rw-r--r-- | demoapp/cliffdemo/simple.py | 10 | ||||
-rw-r--r-- | demoapp/setup.py | 1 |
3 files changed, 16 insertions, 3 deletions
diff --git a/demoapp/cliffdemo/main.py b/demoapp/cliffdemo/main.py index cebf552..9059227 100644 --- a/demoapp/cliffdemo/main.py +++ b/demoapp/cliffdemo/main.py @@ -19,14 +19,16 @@ class DemoApp(App): def prepare_to_run_command(self, cmd): self.log.debug('prepare_to_run_command %s', cmd.__class__.__name__) - def clean_up(self, cmd, result): + def clean_up(self, cmd, result, err): self.log.debug('clean_up %s', cmd.__class__.__name__) + if err: + self.log.debug('got an error: %s', err) def main(argv=sys.argv[1:]): myapp = DemoApp() - myapp.run(argv) + return myapp.run(argv) if __name__ == '__main__': - main(sys.argv[1:]) + sys.exit(main(sys.argv[1:])) diff --git a/demoapp/cliffdemo/simple.py b/demoapp/cliffdemo/simple.py index 2f273b9..1d449d0 100644 --- a/demoapp/cliffdemo/simple.py +++ b/demoapp/cliffdemo/simple.py @@ -12,3 +12,13 @@ class Simple(Command): self.log.info('sending greeting') self.log.debug('debugging') print('hi!') + + +class Error(Command): + "Always raises an error" + + log = logging.getLogger(__name__) + + def run(self, parsed_args): + self.log.info('causing error') + raise RuntimeError('this is the expected exception') diff --git a/demoapp/setup.py b/demoapp/setup.py index ec3dcec..fea934c 100644 --- a/demoapp/setup.py +++ b/demoapp/setup.py @@ -163,6 +163,7 @@ setup( 'cliff.demo': [ 'simple = cliffdemo.simple:Simple', 'two_part = cliffdemo.simple:Simple', + 'error = cliffdemo.simple:Error', ], # 'virtualenvwrapper.initialize': [ # 'user_scripts = virtualenvwrapper.user_scripts:initialize', |