Skip to content

[bug] Recover on simple config.yaml errors #221

@olibre

Description

@olibre

Dotdrop version: v0.32.0
Using dotdrop: from pypi (no dotdrop.sh)

Describe the bug

dotdrop can not start (recover) on any on this two situations:

  • missing profiles:
  • or empty hostname profile

Steps to Reproduce

  1. Remove all config.yaml lines from profiles:

  2. Run dotdrop compare

    [ERR] config file error: invalid config: no profiles found
    
  3. Append in config.yaml (partial revert of the above removal)

     profiles:
       zen:      # my hostname
                 # this is the last line of the file
    
  4. Run dotdrop compare

Traceback (most recent call last):
  File "~/.local/bin/dotdrop", line 10, in <module>
    sys.exit(main())
  File "~/.local/lib/python3.7/site-packages/dotdrop/__init__.py", line 11, in main
    if dotdrop.dotdrop.main():
  File "~/.local/lib/python3.7/site-packages/dotdrop/dotdrop.py", line 612, in main
    o = Options()
  File "~/.local/lib/python3.7/site-packages/dotdrop/options.py", line 125, in __init__
    self._read_config()
  File "~/.local/lib/python3.7/site-packages/dotdrop/options.py", line 182, in _read_config
    self.conf = Cfg(self.confpath, self.profile, debug=self.debug)
  File "~/.local/lib/python3.7/site-packages/dotdrop/cfg_aggregator.py", line 42, in __init__
    self._load()
  File "~/.local/lib/python3.7/site-packages/dotdrop/cfg_aggregator.py", line 48, in _load
    debug=self.debug)
  File "~/.local/lib/python3.7/site-packages/dotdrop/cfg_yaml.py", line 102, in __init__
    self._parse_main_yaml(self.yaml_dict)
  File "~/.local/lib/python3.7/site-packages/dotdrop/cfg_yaml.py", line 183, in _parse_main_yaml
    self.profiles = self._norm_profiles(self.profiles)
  File "~/.local/lib/python3.7/site-packages/dotdrop/cfg_yaml.py", line 387, in _norm_profiles
    if self.key_profile_dotfiles not in v:
TypeError: argument of type 'NoneType' is not iterable

Expected behavior

Better if dotdrop checks that no other (unknwon) YAML section is present, therefore there is no misspelling section (the missing of profiles: is not due of a misspelling error). Then considers the profiles: is empty. Same for the hostname section.

Configuration file

config:
  backup: true
  banner: false
  create: true
  dotpath: dotfiles
  keepdot: true
  link_dotfile_default: nolink
  link_on_import: nolink
  longkey: false
dotfiles:
  f_bashrc:
    src: .bashrc
    dst: ~/.bashrc
  f_gitconfig:
    src: .gitconfig
    dst: ~/.gitconfig
  d_htop:
    src: .config/htop
    dst: ~/.config/htop

Additional information

After removing profiles: (all bottom lines from profiles:)

$ dotdrop --verbose compare
[DEBUG][dotdrop.options.__init__] version: 0.32.0
[DEBUG][dotdrop.options.__init__] config file: config.yaml
[DEBUG][dotdrop.cfg_yaml._parse_main_yaml] settings: {'backup': True, 'banner': False, 'create': True, 'dotpath': '/home/o/.config/dotdrop/dotfiles', 'ignoreempty': True, 'keepdot': True, 'link_dotfile_default': 'nolink', 'link_on_import': 'nolink', 'longkey': False, 'showdiff': False, 'workdir': '/home/o/.config/dotdrop', 'minversion': None, 'diff_command': 'diff -r -u {0} {1}', 'default_actions': [], 'import_actions': [], 'import_configs': [], 'import_variables': [], 'cmpignore': [], 'upignore': [], 'instignore': [], 'func_file': [], 'filter_file': []}
[DEBUG][dotdrop.cfg_yaml._parse_main_yaml] dotfiles: {'f_bashrc': ordereddict([('src', '.bashrc'), ('dst', '~/.bashrc'), ('link', 'nolink'), ('ignoreempty', True)]), 'f_gitconfig': ordereddict([('src', '.gitconfig'), ('dst', '~/.gitconfig'), ('link', 'nolink'), ('ignoreempty', True)]), 'd_ghostwriter': ordereddict([('src', '.config/ghostwriter'), ('dst', '~/.config/ghostwriter'), ('link', 'nolink'), ('ignoreempty', True)]), 'd_htop': ordereddict([('src', '.config/htop'), ('dst', '~/.config/htop'), ('link', 'nolink'), ('ignoreempty', True)]), 'f_bash_profile': ordereddict([('src', '.bash_profile'), ('dst', '~/.bash_profile'), ('link', 'nolink'), ('ignoreempty', True)]), 'f_config': ordereddict([('src', '.ssh/config'), ('dst', '~/.ssh/config'), ('link', 'nolink'), ('ignoreempty', True)]), 'd_geany': ordereddict([('src', '.config/geany'), ('dst', '~/.config/geany'), ('link', 'nolink'), ('ignoreempty', True)]), 'f_config.yaml': ordereddict([('src', '.config/dotdrop/config.yaml'), ('dst', '~/.config/dotdrop/config.yaml'), ('link', 'nolink'), ('ignoreempty', True)])}
[ERR] config file error: invalid config: no profiles found

Extra Info

I was comparing yaml, chezmoi and dotdrop (winner).
My comparaison notes: https://github.com/olibre/GreatPractices#dotfiles-managers

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions