def test_processor(self): parrot = self._get_parrot() wrapped_parrot = argh.wrap_errors([ValueError])(parrot) def failure(err): return 'ERR: ' + str(err) + '!' processed_parrot = argh.wrap_errors(processor=failure)(wrapped_parrot) p = argh.ArghParser() p.set_default_command(processed_parrot) assert run(p, '--dead') == R('', 'ERR: this parrot is no more!\n')
def test_error_wrapped(self): parrot = self._get_parrot() wrapped_parrot = argh.wrap_errors([ValueError])(parrot) p = DebugArghParser() p.set_default_command(wrapped_parrot) assert run(p, '') == R('beautiful plumage\n', '') assert run(p, '--dead') == R('', 'ValueError: this parrot is no more\n')
import monk.errors from .settings import get_app_conf from . import settings from . import caching from .finder import CATEGORIES from . import finder from . import formatting from . import processing from . import reports from . import stats from . import compat nice_errors = argh.wrap_errors( [monk.errors.ValidationError, TypeError, finder.PathDoesNotExist], processor=formatting.format_error) @argh.arg('category', choices=list(CATEGORIES) + ['config']) @argh.arg('pattern', nargs='?', default='') @nice_errors def show(category, pattern, count=False, detailed=False, full=False): # NOTE: --detailed shows *everything* including nested fields like concerns # (and they look horrible), while --full is passed down to the formatter to # print a more complete version of a long field, however some fields may be # hidden with --full. Yes, this is confusing. Yes, it needs refactoring. if category == 'config': for line in showconfig(): yield line
def __call__(self, fn): """Add function `fn` as an available zomni subcommand.""" fn = argh.wrap_errors([GeniError], processor=self.processor)(fn) self.add(fn) return fn