tmux-python / tmuxp

🖥️ Session manager for tmux, build on libtmux.
https://tmuxp.git-pull.com/
MIT License
4.05k stars 231 forks source link

Fail gracefully on invalid YAML configuration #502

Open lordievader opened 5 years ago

lordievader commented 5 years ago

Step 1: Provide a summary of your problem

Tmuxp does not fail gracefully on trying to load an invalid yaml configuration. You get a stack-trace which is not very helpful.

Step 2: Provide tmuxp details

Step 3: Describe your environment

Step 4: Describe the problem:

Steps to reproduce:

  1. Create a config like:
    session_name: tutorial-paper
    windows:
    - window_name: dev window
      layout: tiled
      shell_command_before:
          - cd ~/phd/surveys_and_tutorials
      panes:
          -echo first pane

    Notice the lack of a space in the first pane command.

  2. Try to load the session.
  3. Get a lovely stack trace.

Observed Results:

When loading this configuration you get this stack trace:

Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.6/tmuxp", line 11, in <module>
    load_entry_point('tmuxp==1.5.1', 'console_scripts', 'tmuxp')()
  File "/usr/lib64/python3.6/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib64/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib64/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib64/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib64/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib64/python3.6/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib64/python3.6/site-packages/tmuxp/cli.py", line 812, in command_load
    load_workspace(config[-1], **tmux_options)
  File "/usr/lib64/python3.6/site-packages/tmuxp/cli.py", line 496, in load_workspace
    sconfig = config.expand(sconfig, os.path.dirname(config_file))
  File "/usr/lib64/python3.6/site-packages/tmuxp/config.py", line 283, in expand
    sconf['windows'] = [expand(window, parent=sconf) for window in sconf['windows']]
  File "/usr/lib64/python3.6/site-packages/tmuxp/config.py", line 283, in <listcomp>
    sconf['windows'] = [expand(window, parent=sconf) for window in sconf['windows']]
  File "/usr/lib64/python3.6/site-packages/tmuxp/config.py", line 289, in expand
    pconf = sconf['panes'][p_index] = {}
TypeError: 'str' object does not support item assignment

Expected Results:

I expected the error to contain something about having an invalid YAML configuration.

tony commented 2 years ago

There could be a more user-friendly warning as well.