diff options
author | Georg Brandl <georg@python.org> | 2014-11-10 19:33:20 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-11-10 19:33:20 +0100 |
commit | 02217d4da9afd61b258265b62a755280990fb3e9 (patch) | |
tree | 95570e21a4eb2e89b46a804a0e488f506b815a57 /pygments/cmdline.py | |
parent | c1b7740fb6cdf8fe970883bb74986eeb0bac0645 (diff) | |
download | pygments-02217d4da9afd61b258265b62a755280990fb3e9.tar.gz |
Fix leftover debugging "raise". Add test coverage for errors and exceptions in cmdline_main.
Diffstat (limited to 'pygments/cmdline.py')
-rw-r--r-- | pygments/cmdline.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/pygments/cmdline.py b/pygments/cmdline.py index b6c319cf..c3f00fca 100644 --- a/pygments/cmdline.py +++ b/pygments/cmdline.py @@ -331,10 +331,13 @@ def main(args=sys.argv): opts.pop('-F', None) # select lexer - lexer = opts.pop('-l', None) - if lexer: + lexer = None + + # given by name? + lexername = opts.pop('-l', None) + if lexername: try: - lexer = get_lexer_by_name(lexer, **parsed_opts) + lexer = get_lexer_by_name(lexername, **parsed_opts) except (OptionError, ClassNotFound) as err: print('Error:', err, file=sys.stderr) return 1 @@ -461,12 +464,16 @@ def main(args=sys.argv): right = escapeinside[1] lexer = LatexEmbeddedLexer(left, right, lexer) - # ... and do it! - try: - # process filters - for fname, fopts in F_opts: + # process filters + for fname, fopts in F_opts: + try: lexer.add_filter(fname, **fopts) + except ClassNotFound as err: + print('Error:', err, file=sys.stderr) + return 1 + # ... and do it! + try: if '-s' not in opts: # process whole input as per normal... highlight(code, lexer, fmter, outfile) @@ -494,7 +501,6 @@ def main(args=sys.argv): return 0 except Exception: - raise import traceback info = traceback.format_exception(*sys.exc_info()) msg = info[-1].strip() |