hdl.rec: include record name in error message.

This commit is contained in:
whitequark 2019-01-01 03:39:12 +00:00
parent 031a9e2616
commit 3c07d8d52c
2 changed files with 16 additions and 3 deletions

View file

@ -93,8 +93,12 @@ class Record(Value):
try:
return self.fields[name]
except KeyError:
raise NameError("Record does not have a field '{}'. Did you mean one of: {}?"
.format(name, ", ".join(self.fields))) from None
if self.name is None:
reference = "Unnamed record"
else:
reference = "Record '{}'".format(self.name)
raise NameError("{} does not have a field '{}'. Did you mean one of: {}?"
.format(reference, name, ", ".join(self.fields))) from None
def shape(self):
return sum(len(f) for f in self.fields.values()), False