toggle-corp / alacritty-colorscheme

Change colorscheme of alacritty with ease.
Apache License 2.0
343 stars 35 forks source link

KeyError: 'colors' in case "colors" is not defined in alacritty configuration file #15

Closed monofox closed 3 years ago

monofox commented 3 years ago

Config file contains following information (dict):

{
   "cursor" : {
      "style" : "Beam"
   },
   "font" : {
      "bold" : {
         "family" : "DejaVu Sans Mono for Powerline",
         "style" : "bold"
      },
      "italic" : {
         "family" : "DejaVu Sans Mono for Powerline",
         "style" : "italic"
      },
      "normal" : {
         "family" : "DejaVu Sans Mono for Powerline"
      },
      "size" : 10
   },
   "shell" : {
      "args" : [
         "-l"
      ],
      "program" : "/bin/fish"
   }
}

Executing:

alacritty-colorscheme -C /home/mono/.config/alacritty/alacritty-theme/themes -t solarized_light.yaml solarized_dark.yaml

Results in:

Traceback (most recent call last):
  File "/home/mono/.local/bin/alacritty-colorscheme", line 8, in <module>
    sys.exit(main())
  File "/home/mono/.local/lib/python3.8/site-packages/alacritty_colorscheme/cli.py", line 235, in main
    replace_colorscheme(colors_path, args.config_file,
  File "/home/mono/.local/lib/python3.8/site-packages/alacritty_colorscheme/cli.py", line 155, in replace_colorscheme
    if config_yaml['colors']:
  File "/usr/lib/python3.8/site-packages/ruamel/yaml/comments.py", line 753, in __getitem__
    return ordereddict.__getitem__(self, key)
KeyError: 'colors'

Issue here: https://github.com/toggle-corp/alacritty-colorscheme/blob/ac4a0d3432adfd81a1bc1ece2e20f4bb8815b44c/alacritty_colorscheme/cli.py#L155

It should be catched via try / except KeyError instead of "if" (this would be the pythonic way)

tnagorra commented 3 years ago

Oops! Been working on JS these days.