Skip to content

Commit

Permalink
Properly handle exception from missing vscode config json file (#2728)
Browse files Browse the repository at this point in the history
Today on main this exception is not caught and the Cursorless list
containing all the scopes is not filled which means that Cursorless is
not working if we can't find the vscode json config file.

## Checklist

- [/] I have added
[tests](https://www.cursorless.org/docs/contributing/test-case-recorder/)
- [/] I have updated the
[docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and
[cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet)
- [/] I have not broken the cheatsheet

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
1 parent a7d3488 commit 4b55618
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 0 additions & 2 deletions cursorless-talon/src/apps/vscode_settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import traceback
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -61,7 +60,6 @@ def vscode_get_setting_with_fallback(
return actions.user.vscode_get_setting(key, default_value), False
except Exception:
print(fallback_message)
traceback.print_exc()
return fallback_value, True


Expand Down
13 changes: 10 additions & 3 deletions cursorless-talon/src/marks/decorated_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ def setup_hat_styles_csv(hat_colors: dict[str, str], hat_shapes: dict[str, str])
def init_hats(hat_colors: dict[str, str], hat_shapes: dict[str, str]):
setup_hat_styles_csv(hat_colors, hat_shapes)

vscode_settings_path: Path = actions.user.vscode_settings_path().resolve()
vscode_settings_path: Path | None = None

try:
vscode_settings_path = actions.user.vscode_settings_path().resolve()
except Exception as ex:
print(ex)

def on_watch(path, flags):
global fast_reload_job, slow_reload_job
Expand All @@ -166,10 +171,12 @@ def on_watch(path, flags):
"10s", lambda: setup_hat_styles_csv(hat_colors, hat_shapes)
)

fs.watch(str(vscode_settings_path), on_watch)
if vscode_settings_path is not None:
fs.watch(vscode_settings_path, on_watch)

def unsubscribe():
fs.unwatch(str(vscode_settings_path), on_watch)
if vscode_settings_path is not None:
fs.unwatch(vscode_settings_path, on_watch)
if unsubscribe_hat_styles is not None:
unsubscribe_hat_styles()

Expand Down

0 comments on commit 4b55618

Please sign in to comment.