# HG changeset patch # User Tero Marttila # Date 1234745717 -7200 # Node ID c69a176b36204652fd92636e5f0a6793db2c52ec # Parent 19ff083c2870f6452f54b9066855843612628e77 better string truncation for error messages diff -r 19ff083c2870 -r c69a176b3620 error.py --- a/error.py Mon Feb 16 02:49:06 2009 +0200 +++ b/error.py Mon Feb 16 02:55:17 2009 +0200 @@ -4,6 +4,17 @@ import traceback, sys, cgi, urllib +def truncate (msg, limit) : + """ + Truncate the given message to chars + """ + + if len(msg) > limit : + return msg[:limit-3] + '...' + + else : + return msg + def build_error (exc_info=None, env=None) : """ Dumps out a raw traceback of the given/current exception to stdout. @@ -51,7 +62,7 @@ version = None # the exception type - exception_str = traceback.format_exception_only(*exc_info[:2])[-1][:255] + exception_str = traceback.format_exception_only(*exc_info[:2])[-1] # the exception traceback traceback_lines = traceback.format_exception(*exc_info) @@ -72,7 +83,7 @@ submit_args['revision'] = version if exception_str : - submit_args['summary'] = exception_str + submit_args['summary'] = truncate(exception_str, 140) if traceback_lines : # this is big @@ -108,6 +119,6 @@ traceback = cgi.escape(''.join(traceback_lines)), query_url = query_url, submit_url = submit_url, - submit_url_short = submit_url[:120] + '...' + submit_url_short = truncate(submit_url, 120) )).encode('utf-8'))