porcupine icon indicating copy to clipboard operation
porcupine copied to clipboard

porcupine.settings: Try get an option that doesn't exist --> confusing error message

Open Akuli opened this issue 2 years ago • 0 comments

ThePhilgrim tried to do tab.settings.get("comment_suffix", Optional[str]) without calling .add_option("comment_suffix", ...) anywhere. The error he got was:

porcupine._state ERROR: Error in tkinter callback
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tkinter/__init__.py", line 1948, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "/Users/phil/dev/porcupine-phil/porcupine/menubar.py", line 327, in <lambda>
    get_menu(menu_path).add_command(label=item_text, command=lambda: func(get_filetab()), **kwargs)
                                                                     ^^^^^^^^^^^^^^^^^^^
  File "/Users/phil/dev/porcupine-phil/porcupine/plugins/comment_selected_lines.py", line 20, in comment_or_uncomment
    comment_suffix = tab.settings.get("comment_suffix", Optional[str])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/phil/dev/porcupine-phil/porcupine/settings.py", line 332, in get
    result = self._options[option_name].value
             ~~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'comment_suffix'

A more helpful error would be something like:

LookupError: there is no option named 'comment_suffix' because settings.add_option('comment_suffix', ...) has not been done

Akuli avatar Jul 09 '23 20:07 Akuli