summaryrefslogtreecommitdiff
path: root/pygments
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-11-10 19:33:20 +0100
committerGeorg Brandl <georg@python.org>2014-11-10 19:33:20 +0100
commit02217d4da9afd61b258265b62a755280990fb3e9 (patch)
tree95570e21a4eb2e89b46a804a0e488f506b815a57 /pygments
parentc1b7740fb6cdf8fe970883bb74986eeb0bac0645 (diff)
downloadpygments-02217d4da9afd61b258265b62a755280990fb3e9.tar.gz
Fix leftover debugging "raise". Add test coverage for errors and exceptions in cmdline_main.
Diffstat (limited to 'pygments')
-rw-r--r--pygments/cmdline.py22
-rw-r--r--pygments/formatters/__init__.py4
2 files changed, 16 insertions, 10 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()
diff --git a/pygments/formatters/__init__.py b/pygments/formatters/__init__.py
index 45ceaff6..22eb64c7 100644
--- a/pygments/formatters/__init__.py
+++ b/pygments/formatters/__init__.py
@@ -75,7 +75,7 @@ def get_formatter_by_name(_alias, **options):
"""
cls = find_formatter_class(_alias)
if cls is None:
- raise ClassNotFound("No formatter found for name %r" % _alias)
+ raise ClassNotFound("no formatter found for name %r" % _alias)
return cls(**options)
@@ -95,7 +95,7 @@ def get_formatter_for_filename(fn, **options):
for filename in cls.filenames:
if _fn_matches(fn, filename):
return cls(**options)
- raise ClassNotFound("No formatter found for file name %r" % fn)
+ raise ClassNotFound("no formatter found for file name %r" % fn)
class _automodule(types.ModuleType):