diff options
author | Chad Norvell <chadnorvell@google.com> | 2023-05-04 21:14:26 +0000 |
---|---|---|
committer | CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-05-04 21:14:26 +0000 |
commit | b9e9f69ab31e2ce3ff07adbd70cd93f6d6f3e061 (patch) | |
tree | b6ca9caffbfa2e6007c8efbb5f25322381672d96 /pw_ide | |
parent | 3ecc4ba9b11b7a3f13b7dae31a813ae7a70680ab (diff) | |
download | pigweed-b9e9f69ab31e2ce3ff07adbd70cd93f6d6f3e061.tar.gz |
pw_ide: Fix edge case failure UX
- Fail more gracefully if the default target isn't available
- Fix an unhandled KeyError obscured by pw_cli
- Don't dump tracebacks on sys.exit, since we already provide more
direct feedback to the user
Change-Id: If1f229c6519e33a538c0426d13eb9010535928b3
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/140590
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Chad Norvell <chadnorvell@google.com>
Diffstat (limited to 'pw_ide')
-rw-r--r-- | pw_ide/py/pw_ide/commands.py | 53 | ||||
-rw-r--r-- | pw_ide/py/pw_ide/cpp.py | 3 |
2 files changed, 36 insertions, 20 deletions
diff --git a/pw_ide/py/pw_ide/commands.py b/pw_ide/py/pw_ide/commands.py index c02f8552a..94bc95a5b 100644 --- a/pw_ide/py/pw_ide/commands.py +++ b/pw_ide/py/pw_ide/commands.py @@ -96,7 +96,7 @@ def cmd_sync( for command in pw_ide_settings.sync: _LOG.debug("Running: %s", command) - subprocess.run(shlex.split(command), check=True) + subprocess.run(shlex.split(command)) if pw_ide_settings.editor_enabled('vscode'): cmd_vscode() @@ -177,7 +177,12 @@ def cmd_vscode( default. """ if not pw_ide_settings.editor_enabled('vscode'): - reporter.wrn('Visual Studio Code support is disabled in settings!') + reporter.wrn( + 'Visual Studio Code support is disabled in settings! If this is ' + 'unexpected, see this page for information on enabling support: ' + 'https://pigweed.dev/pw_ide/' + '#pw_ide.settings.PigweedIdeSettings.editors' + ) sys.exit(1) if not vscode.DEFAULT_SETTINGS_PATH.exists(): @@ -559,8 +564,8 @@ def cmd_cpp( # pylint: disable=too-many-arguments, too-many-locals, too-many-br default = False should_update_ides = _process_compdbs(reporter, pw_ide_settings) - if state.current_target is None: - use_default_target = True + if state.current_target is None: + use_default_target = True if use_default_target: defined_default = pw_ide_settings.default_target @@ -585,34 +590,42 @@ def cmd_cpp( # pylint: disable=too-many-arguments, too-many-locals, too-many-br if target_to_set is not None: default = False + reporter.info(f'Setting C/C++ analysis target to: {target_to_set}') try: - CppIdeFeaturesState(pw_ide_settings).current_target = state.targets[ + CppIdeFeaturesState( + pw_ide_settings + ).current_target = state.targets.get(target_to_set, None) + + if str(CppIdeFeaturesState(pw_ide_settings).current_target) != str( target_to_set - ] + ): + reporter.err(f'Failed to set target to {target_to_set}!') + reporter.wrn( + [ + 'You have tried to set a target that is not available.', + 'Run `pw ide cpp --list` to show available targets.', + f'If you expected {target_to_set} to be in that list', + 'and it is not, you may need to use your build system', + 'generate a compilation database.', + ] + ) + sys.exit(1) + should_update_ides = True except InvalidTargetException: reporter.err( - [ - f'Invalid target! {target_to_set} not among the ' - 'defined targets.', - 'Check .pw_ide.yaml or .pw_ide.user.yaml for defined ' - 'targets.', - ] + f'Invalid target! {target_to_set} not among the ' + 'defined targets.' ) sys.exit(1) except MissingCompDbException: - reporter.err( - [ - f'File not found for target! {target_to_set}', - 'Did you run pw ide cpp --process ' - '{path to compile_commands.json}?', - ] - ) + reporter.err(f'File not found for target! {target_to_set}') sys.exit(1) reporter.new( - 'Set C/C++ language server analysis target to: ' f'{target_to_set}' + 'Set C/C++ language server analysis target to: ' + f'{CppIdeFeaturesState(pw_ide_settings).current_target}' ) if should_update_ides: diff --git a/pw_ide/py/pw_ide/cpp.py b/pw_ide/py/pw_ide/cpp.py index 1823ceaba..2facbd297 100644 --- a/pw_ide/py/pw_ide/cpp.py +++ b/pw_ide/py/pw_ide/cpp.py @@ -96,6 +96,9 @@ class CppIdeFeaturesTarget: num_commands: int is_enabled: bool = True + def __str__(self) -> str: + return self.name + def serialized(self) -> Dict[str, Any]: return { **asdict(self), |