From ae0c1f711213a0899b6388dd6eca7bb23be6fdff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 22 Jul 2014 14:20:01 +0200 Subject: [PATCH] htmlreport: don't crash when pygments fails to determine filetype of a file we want to highlight. This happens for files with no extension (for example "foo" instead of "foo.c"). --- htmlreport/cppcheck-htmlreport | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport index 1ff69fb2d..c2a715949 100755 --- a/htmlreport/cppcheck-htmlreport +++ b/htmlreport/cppcheck-htmlreport @@ -359,7 +359,14 @@ if __name__ == '__main__': output_file.write(" %s %s" % (data['htmlfile'], error['line'], error['id'], error['line'])) output_file.write(HTML_HEAD_END) - lexer = guess_lexer_for_filename(source_filename, '') + try: + lexer = guess_lexer_for_filename(source_filename, '') + except: + sys.stderr.write("ERROR: Couldn't determine lexer for the file' " + source_filename + " '. Won't be able to syntax highlight this file.") + output_file.write("\n Could not generated content because pygments failed to retrieve the determine code type.") + output_file.write("\n Sorry about this.") + continue + if options.source_encoding: lexer.encoding = options.source_encoding