cursorless-dev / cursorless

Don't let the cursor slow you down
https://www.cursorless.org/
MIT License
1.15k stars 81 forks source link

Improve error message when using snippet wrap functionality and `variable_name` is not specified in wrapper_snippets.csv #1930

Open bellicapax opened 1 year ago

bellicapax commented 1 year ago

When a user has added a snippet to the wrapper_snippets.csv file, but has left off the name of the variable that will be replaced in the snippet, (e.g., for each, forEach instead of for each, forEach.body cursorless will respond with this error message:

2023-09-28 14:55:44.909 ERROR     3: user\cursorless-talon\src\actions\wrap.py:26| m.cursorless_wrapper_paired_delimiter
    2:                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    1:                       talon\grammar\vm.py:96| 
AttributeError: cursorless_wrapper_paired_delimiter
[The below error was raised while handling the above exception(s)]
2023-09-28 14:55:44.916 ERROR cb error topic="phrase" cb=SpeechSystem.engine_event
   25:                      talon\lib\_thread.py:19  * # cron thread
   24:                              threading.py:995 * 
   23:                              threading.py:1038* 
   22:                              threading.py:975 * 
   21:                             talon\cron.py:156 | 
   20:                              talon\vad.py:23  | 
   19:                              talon\vad.py:129 | 
   18:          talon\scripting\speech_system.py:370 | 
   17:                      talon\engines\w2l.py:757 | 
   16:               talon\scripting\dispatch.py:134 | # 'phrase' main:EngineProxy._redispatch()
   15:          talon\scripting\speech_system.py:67  | 
   14: ----------------------------------------------# [stack splice]
   13:               talon\scripting\dispatch.py:134 | # 'phrase' main:SpeechSystem.engine_event()
   12:          talon\scripting\speech_system.py:482 | 
   11:                       talon\grammar\vm.py:195 | 
   10:                       talon\grammar\vm.py:162 | 
    9:          talon\scripting\speech_system.py:500 | 
    8:                       talon\grammar\vm.py:195 | 
    7:                       talon\grammar\vm.py:162 | 
    6:          talon\scripting\speech_system.py:502 | 
    5:                  talon\scripting\types.py:423 | 
    4: user\cursorless-talon\src\actions\wrap.py:33  | snippet_name, variable_name = parse_sn..
    3:                                                                  
    2: user\cursorless-talon\src\actions\wrap.py:49  | [snippet_name, variable_name] = snippet_location.split(".")
    1:                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 1)
Collapse

This error message could be improved to call out that the name of the variable that will be replaced by what is being wrapped is missing. That is, one of the entries from the variables object inside the corresponding .cursorless_snippets file should be included on that line in the CSV after a period and the name of the snippet.

bellicapax commented 1 year ago

This is a more specific implementation of the larger problem mentioned here: #1928