Skip to content

Commit

Permalink
verify int nature of start/length at schema load time for better erro…
Browse files Browse the repository at this point in the history
…r reporting
  • Loading branch information
JoeGermuska committed Oct 3, 2011
1 parent f2dd103 commit fae0d3c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions csvkit/convert/fixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class SchemaDecoder(object):
"""
Extracts column, start, and length columns from schema rows. Once instantiated, each time the instance is called with a row, a (column,start,length) tuple will be returned based on values in that row and the constructor kwargs.
"""
REQUIRED_COLUMNS = ['column', 'start', 'length']
REQUIRED_COLUMNS = [('column', None), ('start', int), ('length', int)]

start = None
length = None
Expand All @@ -108,9 +108,12 @@ def __init__(self, header, **kwargs):
"""
Constructs a schema row decoder.
"""
for p in self.REQUIRED_COLUMNS:
for p, val_type in self.REQUIRED_COLUMNS:
try:
setattr(self, p, header.index(p))
if val_type:
setattr(self, p, val_type(header.index(p)))
else:
setattr(self, p, header.index(p))
except ValueError:
raise ValueError('A column named "%s" must exist in the schema file.' % (p))

Expand Down

0 comments on commit fae0d3c

Please sign in to comment.