Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need better error for missing file in pytmc template #326

Open
ZLLentz opened this issue Feb 9, 2024 · 0 comments
Open

Need better error for missing file in pytmc template #326

ZLLentz opened this issue Feb 9, 2024 · 0 comments

Comments

@ZLLentz
Copy link
Member

ZLLentz commented Feb 9, 2024

If your PLC project repo is missing a file (any file, even one not related to the ioc build), the pytmc template command fails with a confusing error:

Traceback (most recent call last):
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/bin/pytmc", line 10, in <module>
    sys.exit(main())
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/bin/pytmc.py", line 106, in main
    func(**kwargs)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/bin/template.py", line 830, in main
    raise stashed_exception
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/bin/template.py", line 821, in main
    template_args.update(projects_to_dict(*projects))
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/bin/template.py", line 268, in projects_to_dict
    for key, value in project_to_dict(path).items():
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/bin/template.py", line 219, in project_to_dict
    projects = {fn: parser.parse(fn) for fn in project_files}
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/bin/template.py", line 219, in <dictcomp>
    projects = {fn: parser.parse(fn) for fn in project_files}
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 51, in parse
    return TwincatItem.parse(root, filename=fn, parent=parent)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 407, in parse
    return cls(element, parent=parent, filename=filename, name=name)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 224, in __init__
    self._add_children(element)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 300, in _add_children
    self._add_child(child_element)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 309, in _add_child
    child = self.parse(element, parent=self, filename=self.filename)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 407, in parse
    return cls(element, parent=parent, filename=filename, name=name)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 224, in __init__
    self._add_children(element)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 300, in _add_children
    self._add_child(child_element)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 309, in _add_child
    child = self.parse(element, parent=self, filename=self.filename)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 407, in parse
    return cls(element, parent=parent, filename=filename, name=name)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 224, in __init__
    self._add_children(element)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 2134, in _add_children
    self._finish_lazy_loading(self._xti_files)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 347, in _finish_lazy_loading
    self._children[idx] = child.load(file_map)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 455, in load
    obj._finish_lazy_loading(file_map)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 349, in _finish_lazy_loading
    child._finish_lazy_loading(file_map)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 347, in _finish_lazy_loading
    self._children[idx] = child.load(file_map)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 455, in load
    obj._finish_lazy_loading(file_map)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 349, in _finish_lazy_loading
    child._finish_lazy_loading(file_map)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 347, in _finish_lazy_loading
    self._children[idx] = child.load(file_map)
  File "/cds/group/pcds/pyps/conda/py39/envs/pcds-5.8.1/lib/python3.9/site-packages/pytmc/parser.py", line 453, in load
    info = file_map[self.key]
KeyError: (<class ‘pytmc.parser.Box’>, ‘15’, ‘ffo.xti’)

It's good that this gets caught in some capacity, but the error should be made more clear, e.g. something like:
"RuntimeError: file named {filename} missing from the repo!"

We can probably handle this by catching a KeyError in this line:

info = file_map[self.key]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant