home-assistant / home-assistant/core

component: huawei-lte: excessive stack traces if modem is unavilabale

Open
#55,495 22 comments 0 reactions 0 assignees View on GitHub
integration: huawei_lte
Dominant language
Python
Stars
90.5k
Forks
38.6k
Avg merge
1d 2h
Merged PRs (30d)
597

Description

### The problem

If the LTE modem is unavailable, you get ~80 or so lines of stack trace, due to unhandled exceptions: eg:
```
hass | 2021-08-31 09:34:13 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry B818-263 for huawei_lte
hass | Traceback (most recent call last):
hass | File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 169, in _new_conn
hass | conn = connection.create_connection(
hass | File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 96, in create_connection
hass | raise err
hass | File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 86, in create_connection
hass | sock.connect(sa)
hass | OSError: [Errno 101] Network unreachable
hass |
hass | During handling of the above exception, another exception occurred:
hass |
hass | Traceback (most recent call last):
hass | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen
hass | httplib_response = self._make_request(
hass | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 394, in _make_request
hass | conn.request(method, url, **httplib_request_kw)
hass | File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 234, in request
hass | super(HTTPConnection, self).request(method, url, body=body, headers=headers)
hass | File "/usr/local/lib/python3.9/http/client.py", line 1257, in request
hass | self._send_request(method, url, body, headers, encode_chunked)
hass | File "/usr/local/lib/python3.9/http/client.py", line 1303, in _send_request
hass | self.endheaders(body, encode_chunked=encode_chunked)
hass | File "/usr/local/lib/python3.9/http/client.py", line 1252, in endheaders
hass | self._send_output(message_body, encode_chunked=encode_chunked)
hass | File "/usr/local/lib/python3.9/http/client.py", line 1012, in _send_output
hass | self.send(msg)
hass | File "/usr/local/lib/python3.9/http/client.py", line 952, in send
hass | self.connect()
hass | File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 200, in connect
hass | conn = self._new_conn()
hass | File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 181, in _new_conn
hass | raise NewConnectionError(
hass | urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [Errno 101] Network unreachable
hass |
hass | During handling of the above exception, another exception occurred:
hass |
hass | Traceback (most recent call last):
hass | File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 439, in send
hass | resp = conn.urlopen(
hass | File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen
hass | retries = retries.increment(
hass | File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 574, in increment
hass | raise MaxRetryError(_pool, url, error or ResponseError(cause))
hass | urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.8.1', port=80): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 101] Network unreachable'))
hass |
hass | During handling of the above exception, another exception occurred:
hass |
hass | Traceback (most recent call last):
hass | File "/usr/src/homeassistant/homeassistant/config_entries.py", line 293, in async_setup
hass | result = await component.async_setup_entry(hass, self) # type: ignore
hass | File "/usr/src/homeassistant/homeassistant/components/huawei_lte/__init__.py", line 362, in async_setup_entry
hass | connection = await hass.async_add_executor_job(get_connection)
hass | File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
hass | result = self.fn(*self.args, **self.kwargs)
hass | File "/usr/src/homeassistant/homeassistant/components/huawei_lte/__init__.py", line 356, in get_connection
hass | connection = AuthorizedConnection(
hass | File "/usr/local/lib/python3.9/site-packages/huawei_lte_api/AuthorizedConnection.py", line 22, in __init__
hass | super().__init__(clear_url, timeout=timeout)
hass | File "/usr/local/lib/python3.9/site-packages/huawei_lte_api/Connection.py", line 45, in __init__
hass | self._initialize_csrf_tokens_and_session()
hass | File "/usr/local/lib/python3.9/site-packages/huawei_lte_api/Connection.py", line 109, in _initialize_csrf_tokens_and_session
hass | response = self.session.get(self.url, timeout=self.timeout)
hass | File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 555, in get
hass | return self.request('GET', url, **kwargs)
hass | File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
hass | resp = self.send(prep, **send_kwargs)
hass | File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
hass | r = adapter.send(request, **kwargs)
hass | File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 516, in send
hass | raise ConnectionError(e, request=request)
hass | requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.8.1', port=80): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 101] Network unreachable'))
```
This seems excessive. just the plain ``` Failed to establish a new connection: [Errno 101] Network unreachable'))``` would be more than sufficient.

### What is version of Home Assistant Core has the issue?

2021.8.8

### What was the last working version of Home Assistant Core?

_No response_

### What type of installation are you running?

Home Assistant Container

### Integration causing the issue

huawei-lte

### Link to integration documentation on our website

https://www.home-assistant.io/integrations/huawei_lte/

### Example YAML snippet

```yaml
n/a
```

### Anything in the logs that might be useful for us?

```txt
Logs included above
```

### Additional information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in homeassistant/components/huawei_lte/__init__.py at async_setup_entry and get_connection, the entry points shown in the traceback. Review how an unavailable modem exception is handled during setup. Done means the failure reports a concise connection error rather than the full nested stack trace.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.