diff options
author | jaseg <git@jaseg.de> | 2022-01-24 11:55:19 +0100 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2022-01-24 11:55:19 +0100 |
commit | 4a6d76c557caf7263ab57e5fe840d28aa3356621 (patch) | |
tree | 98d9cd7f87cbedad58521c1fbbbc5dce649598eb /gerbonara/gerber/excellon.py | |
parent | 269087bead401513cfadc0d912bfad2b6ec8b9c6 (diff) | |
download | gerbonara-4a6d76c557caf7263ab57e5fe840d28aa3356621.tar.gz gerbonara-4a6d76c557caf7263ab57e5fe840d28aa3356621.tar.bz2 gerbonara-4a6d76c557caf7263ab57e5fe840d28aa3356621.zip |
Improve error messages
Diffstat (limited to 'gerbonara/gerber/excellon.py')
-rwxr-xr-x | gerbonara/gerber/excellon.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/gerbonara/gerber/excellon.py b/gerbonara/gerber/excellon.py index b5c9221..02e63d7 100755 --- a/gerbonara/gerber/excellon.py +++ b/gerbonara/gerber/excellon.py @@ -175,7 +175,7 @@ class ExcellonFile(CamFile): @classmethod def from_string(kls, data, settings=None, filename=None, plated=None): parser = ExcellonParser(settings) - parser._do_parse(data) + parser.do_parse(data, filename=filename) return kls(objects=parser.objects, comments=parser.comments, import_settings=settings, generator_hints=parser.generator_hints, filename=filename) @@ -347,9 +347,12 @@ class ExcellonParser(object): self.comments = [] self.generator_hints = [] - def _do_parse(self, data): + def do_parse(self, data, filename=None): + # filename arg is for error messages + filename = filename or '<unknown>' + leftover = None - for line in data.splitlines(): + for lineno, line in enumerate(data.splitlines(), start=1): line = line.strip() if not line: @@ -373,9 +376,8 @@ class ExcellonParser(object): try: if not self.exprs.handle(self, line): raise ValueError('Unknown excellon statement:', line) - except: - print('Original line was:', line) - raise + except Exception as e: + raise SyntaxError(f'{filename}:{lineno} "{line}": {e}') from e exprs = RegexMatcher() @@ -661,7 +663,7 @@ class ExcellonParser(object): def handle_absolute_mode(self, match): if int(match['X'] or 0) != 0 or int(match['Y'] or 0) != 0: # Siemens tooling likes to include a meaningless G93X0Y0 after its header. - raise SyntaxError('G93 zero set command is not supported.') + raise NotImplementedError('G93 zero set command is not supported.') self.generator_hints.append('siemens') @exprs.match('ICI,?(ON|OFF)') |