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

Empty config files can cause errors #523

Open
MJJoyce opened this issue Apr 4, 2024 · 1 comment
Open

Empty config files can cause errors #523

MJJoyce opened this issue Apr 4, 2024 · 1 comment

Comments

@MJJoyce
Copy link
Member

MJJoyce commented Apr 4, 2024

AIT can fail to gracefully handle empty configuration dictionary files. Adding some checks to make this more robust would be valuable even though it's unlikely most users will run into issues here.

For example, AIT will properly return an empty dictionary if you load the dictionary from a component that doesn't have a configuration file provided. If you edit config.yaml and remove the default command dictionary:

@@ -11,7 +11,7 @@ default:
         directory: ../scripts

     cmddict:
-        filename:  cmd.yaml
+      #filename:  cmd.yaml

You get nothing when you request a dictionary.

>>> cmd.getDefaultDict()
{}

However, if you pass an empty configuration dictionary the dictionary load will fail:

>>> ait.core.cmd.getDefaultDict()
2024-04-04T13:08:05.331 | INFO     | AIT-Core/config/cmd.yaml modified - make a new binary pickle cache file.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "AIT-Core/ait/core/cmd.py", line 508, in getDefaultDict
    return util.getDefaultDict(__name__, "cmddict", loader, reload)
  File "AIT-Core/ait/core/util.py", line 313, in getDefaultDict
    default = ObjectCache(filename, loader).load()
  File "AIT-Core/ait/core/util.py", line 83, in load
    self._dict = self._loader(self.filename)
  File "AIT-Core/ait/core/util.py", line 217, in create
    return create.cls(*args, **kwargs)
  File "AIT-Core/ait/core/cmd.py", line 410, in __init__
    self.load(args[0])
  File "AIT-Core/ait/core/cmd.py", line 490, in load
    cmds = handle_includes(cmds)
  File "AIT-Core/ait/core/cmd.py", line 536, in handle_includes
    for d in defns:
TypeError: 'NoneType' object is not iterable
>>>
@jllamas
Copy link

jllamas commented Apr 8, 2024

Hey @MJJoyce, thanks for posting this.

Some background for context: We have external users that need to see TLM, but have restrictions on the CMD dictionary. Since the server is on the edge serving the TLM, we opt'ed to omit the CMD dict altogether. Setting the cmd.yml to an empty file causes the OpenMCT API fail.

The simple solution was to add at least 1 dummy command to the CMD.yml file.

- !Command
  name: NOPE_NOOP
  opcode: 0x0000000
  desc: "Dummy CMD to keep AIT happy"
  ccsds:
    version: 0
    type: 0
    seqflags: 0
    seqcnt: 0
    length: 0
    apid: 0
    secondary: 0

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

2 participants