dvd-dev / dvd-dev/hilo

Refactor generic exception handling (bare except)

Open
#889 0 comments 0 reactions 0 assignees View on GitHub
refactoring
Dominant language
Python
Stars
248
Forks
46
Avg merge
4h 4m
Merged PRs (30d)
26

Description

## Version of the custom_component

## Configuration

```yaml
N/A
```

## Describe the bug

There are places in the codebase where exception handling is too generic, such as with `except Exception` or bare `except:` blocks. This practice can hide unexpected errors and complicate debugging and maintenance.

Below is a concrete example found in the codebase where a generic exception handler is used:

---

**Example: Bare except block in Hilo class**

[custom_components/hilo/__init__.py](https://github.com/dvd-dev/hilo/blob/f8cd20a620201f02ed9611d76a829adff56fbcd1/custom_components/hilo/__init__.py#L381-L392)
```python
try:
...
except Exception as e:
LOG.error("Error in websocket handler %s: %s", handler_name, e)
LOG.error(traceback.format_exc())
```

**Other similar cases may be present in the codebase.** Please consider refactoring these blocks to handle only the appropriate exceptions explicitly.

---

Improving exception handling will make the codebase more robust and easier to debug and maintain.

## Debug log

```text
N/A
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.