Replace RuntimeError exceptions
- Dominant language
- Python
- Stars
- 9
- Forks
- 9
- Avg merge
- 12d 12h
- Merged PRs (30d)
- 2
Description
The current code over-uses the python exception hierarchy, especially `RuntimeError` exceptions, where custom exception classes would be better. This makes it difficult to differentiate between legitimate errors and known or expected conditions.
For example, `source/fab/tools/tool.py` contains the following:
```py
if self._is_available is False:
raise RuntimeError(f"Tool '{self.name}' is not available to run "
f"'{command}'.")
try:
res = subprocess.run(command, capture_output=capture_output,
env=env, cwd=cwd, check=False)
except FileNotFoundError as err:
raise RuntimeError(f"Command '{command}' could not be "
f"executed.") from err
if res.returncode != 0:
msg = (f'Command failed with return code {res.returncode}:\n'
f'{command}')
if res.stdout:
msg += f'\n{res.stdout.decode()}'
if res.stderr:
msg += f'\n{res.stderr.decode()}'
raise RuntimeError(msg)
```
Which prevents the caller from determining whether the condition was a configuration issue, whether it was a legitimate failure because the compiler being targeted was not installed, or whether an error occurred running the command.
Contributor guide
Assessment
This issue has not been assessed yet.