cmmorrow / build-magic

A general purpose build/install/deploy tool.
MIT License
9 stars 2 forks source link

Running `build-magic --info` on a Config File without metadata gives an error #95

Closed cmmorrow closed 2 years ago

cmmorrow commented 2 years ago

Describe the bug When running build-magic --info config.yaml, where config.yaml doesn't have any metadata, the following error is raised:

Traceback (most recent call last):
  File "/Users/chrismorrow/.pyenv/versions/3.9.2/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/chrismorrow/.pyenv/versions/3.9.2/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/chrismorrow/repos/build-magic/build_magic/__main__.py", line 7, in <module>
    build_magic()
  File "/Users/chrismorrow/build-magic/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/Users/chrismorrow/build-magic/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/Users/chrismorrow/build-magic/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/chrismorrow/build-magic/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/Users/chrismorrow/repos/build-magic/build_magic/cli.py", line 254, in build_magic
    execute_info_subcommand(ctx=ctx, config_files=args)
  File "/Users/chrismorrow/repos/build-magic/build_magic/cli.py", line 492, in execute_info_subcommand
    get_config_info(cfg, show_filename=show_filenames)
  File "/Users/chrismorrow/repos/build-magic/build_magic/cli.py", line 472, in get_config_info
    space = max(spacing) + 1
ValueError: max() arg is an empty sequence

To Reproduce Steps to reproduce the behavior:

  1. Create a new "valid" Config File named config.yaml that has no metadata fields.
  2. Run build-magic --info config.yaml.

Expected behavior Python errors should be properly handled. The problem is occurring in cli.py on line 472:

space = max(spacing) + 1

The fix is to add a check to make sure spacing is not an empty list. If spacing is an empty list, space should default to a value of 1.