]> git.donarmstrong.com Git - deb_pkgs/autorandr.git/commitdiff
Improve error messages: Include file name if the error didn't occur in autorandr.py
authorPhillip Berndt <phillip.berndt@googlemail.com>
Wed, 14 Dec 2016 11:55:08 +0000 (12:55 +0100)
committerPhillip Berndt <phillip.berndt@googlemail.com>
Wed, 14 Dec 2016 11:55:08 +0000 (12:55 +0100)
autorandr.py

index aa4b8f2483169ac1c38175c7a630c21e462291f3..bde96346db29cdd768b460f649a07627978ac6aa 100755 (executable)
@@ -99,18 +99,25 @@ class AutorandrException(Exception):
             while trace.tb_next:
                 trace = trace.tb_next
             self.line = trace.tb_lineno
+            self.file_name = trace.tb_frame.f_code.co_filename
         else:
             try:
                 import inspect
-                self.line = inspect.currentframe().f_back.f_lineno
+                frame = inspect.currentframe().f_back
+                self.line = frame.f_lineno
+                self.file_name = frame.f_code.co_filename
             except:
                 self.line = None
+                self.file_name = None
             self.original_exception = None
 
+        if os.path.abspath(self.file_name) == os.path.abspath(sys.argv[0]):
+            self.file_name = None
+
     def __str__(self):
         retval = [ self.message ]
         if self.line:
-            retval.append(" (line %d)" % self.line)
+            retval.append(" (line %d%s)" % (self.line, ("; %s" % self.file_name) if self.file_name else ""))
         if self.original_exception:
             retval.append(":\n  ")
             retval.append(str(self.original_exception).replace("\n", "\n  "))