From 2701a22db4243495080d53192033f1ef07f7625c Mon Sep 17 00:00:00 2001 From: facetoe Date: Sat, 28 Mar 2015 19:10:13 +0800 Subject: [PATCH] Add method to truncate long error messages. --- i3pystatus/core/threading.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/i3pystatus/core/threading.py b/i3pystatus/core/threading.py index 6063c54..2465551 100644 --- a/i3pystatus/core/threading.py +++ b/i3pystatus/core/threading.py @@ -75,10 +75,18 @@ class ExceptionWrapper(Wrapper): sys.stderr.flush() if hasattr(self.workload, "output"): self.workload.output = { - "full_text": "{}: {}".format(self.workload.__class__.__name__, sys.exc_info()[1]), + "full_text": "{}: {}".format(self.workload.__class__.__name__, + self.format_error(str(sys.exc_info()[1]))), "color": "#FF0000", } + def format_error(self, exception_message): + if hasattr(self.workload, 'max_error_len'): + error_len = self.workload.max_error_len + return exception_message[:error_len] + '...' if len(exception_message) > error_len else exception_message + else: + return exception_message + class WorkloadWrapper(Wrapper): time = 0.0