Permalink
Browse files

Improve exception formatting.

  • Loading branch information...
1 parent e96e312 commit 7c046ca85591923b817b081535a410a54bcff903 @malthe committed Apr 18, 2012
Showing with 33 additions and 4 deletions.
  1. +9 −0 CHANGES.rst
  2. +24 −4 src/chameleon/exc.py
View
@@ -3,8 +3,17 @@ Changes
In next release ...
+Features:
+
+- In exception output, long filenames are now truncated to 60
+ characters of output, preventing line wrap which makes it difficult
+ to scan the exception output.
+
Bugfixes:
+- Include filename and location in exception output for exceptions
+ raised during compilation.
+
- If a trivial translation substitution variable is given (i.e. an
empty string), simply ignore it. This fixes issue #106.
View
@@ -137,7 +137,22 @@ def __reduce__(self):
return reconstruct_exc, (type(self), self.__dict__)
def __str__(self):
- return '%s ("%s").' % (self.msg, self.token)
+ text = "%s\n\n" % self.msg
+ text += " - String: \"%s\"" % self.token
+
+ if self.filename:
+ text += "\n"
+ text += " - Filename: %s" % self.filename
+
+ try:
+ line, column = self.token.location
+ except AttributeError:
+ pass
+ else:
+ text += "\n"
+ text += " - Location: (%d:%d)" % (line, column)
+
+ return text
def __repr__(self):
try:
@@ -232,10 +247,15 @@ def __call__(self):
out.append(" - Stream: %s" % s)
out.append(" %s" % marker)
+ if filename:
+ if len(filename) > 60:
+ filename = "... " + filename[-56:]
+ else:
+ filename = "<string>"
+
out.append(" - Expression: \"%s\"" % expression)
- out.append(" - Filename: %s" % (filename or "<string>"))
+ out.append(" - Filename: %s" % filename)
out.append(" - Location: (%d:%d)" % (line, column))
- out.append("")
if filename and line and column:
try:
@@ -252,7 +272,7 @@ def __call__(self):
)
out.append(" - Source: %s" % s)
- out.append(" %s" % marker)
+ out.append("")
break
finally:
f.close()

0 comments on commit 7c046ca

Please sign in to comment.