Skip to content

Commit 199a649

Browse files
committed
[validation] Shorten ValidationError repr string
1 parent 30c72cf commit 199a649

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

odml/validation.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
from . import dtypes
1111

12+
try:
13+
unicode = unicode
14+
except NameError:
15+
unicode = str
16+
1217
LABEL_ERROR = 'error'
1318
LABEL_WARNING = 'warning'
1419

@@ -83,9 +88,15 @@ def path(self):
8388
return self.obj.get_path()
8489

8590
def __repr__(self):
86-
return "<ValidationError(%s):%s '%s'>" % (self.rank,
87-
self.obj,
88-
self.msg)
91+
# Cleanup the odml object print strings
92+
print_str = unicode(self.obj).split()[0].split("[")[0].split(":")[0]
93+
# Document has no name attribute and should not print id or name info
94+
if hasattr(self.obj, "name"):
95+
if self.obj.name and self.obj.name != self.obj.id:
96+
print_str = "%s[%s]" % (print_str, self.obj.name)
97+
else:
98+
print_str = "%s[%s]" % (print_str, self.obj.id)
99+
return "Validation%s: %s '%s'" % (self.rank.capitalize(), print_str, self.msg)
89100

90101

91102
class Validation(object):

0 commit comments

Comments
 (0)