summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2015-02-26 18:16:25 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2015-02-26 18:16:25 +0200
commit5c16a116ec2db9d19e42c5682cbfbf4f2b87ad87 (patch)
tree3be33a31d068f47cda7b3dee6ec4bb59e2c53bc5 /generator
parent4a6580726ec2a0b71d8f01133d5c38a469eac497 (diff)
Better error messages for syntax errors in .options file
Diffstat (limited to 'generator')
-rwxr-xr-xgenerator/nanopb_generator.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index 7ee06523..82602908 100755
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -1126,14 +1126,28 @@ def read_options_file(infile):
[(namemask, options), ...]
'''
results = []
- for line in infile:
+ for i, line in enumerate(infile):
line = line.strip()
if not line or line.startswith('//') or line.startswith('#'):
continue
parts = line.split(None, 1)
+
+ if len(parts) < 2:
+ sys.stderr.write("%s:%d: " % (infile.name, i + 1) +
+ "Option lines should have space between field name and options. " +
+ "Skipping line: '%s'\n" % line)
+ continue
+
opts = nanopb_pb2.NanoPBOptions()
- text_format.Merge(parts[1], opts)
+
+ try:
+ text_format.Merge(parts[1], opts)
+ except Exception, e:
+ sys.stderr.write("%s:%d: " % (infile.name, i + 1) +
+ "Unparseable option line: '%s'. " % line +
+ "Error: %s\n" % str(e))
+ continue
results.append((parts[0], opts))
return results