Skip to content

Commit

Permalink
config_flow: Print exception info to log
Browse files Browse the repository at this point in the history
We currently consume every `OmnikInverterError` and only raise a
`cannot_connect` error to the UI, with no context whatsoever .  It could
be a connection error, but also a message that fails to parse/verify.
Printing the stacktrace to the log so that we can better aid our users
when they encounter issues; this also makes it easier to understand and
solve compatibility problems with other brands that use a very similar
yet not identical message format.
  • Loading branch information
MarijnS95 committed Aug 20, 2023
1 parent 9924c2b commit bc36678
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions custom_components/omnik_inverter/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
CONFIGFLOW_VERSION,
DEFAULT_SCAN_INTERVAL,
DOMAIN,
LOGGER,
)


Expand Down Expand Up @@ -128,6 +129,7 @@ async def async_step_setup(
) as client:
await client.perform_request()
except OmnikInverterError:
LOGGER.exception("Failed to connect to the Omnik")
errors["base"] = "cannot_connect"
except Exception as error: # pylint: disable=broad-exception-caught
errors["base"] = str(error)
Expand Down Expand Up @@ -178,6 +180,7 @@ async def async_step_setup_html(
) as client:
await client.perform_request()
except OmnikInverterError:
LOGGER.exception("Failed to connect to the Omnik")
errors["base"] = "cannot_connect"
except Exception as error: # pylint: disable=broad-exception-caught
errors["base"] = str(error)
Expand Down Expand Up @@ -231,6 +234,7 @@ async def async_step_setup_tcp(
) as client:
await client.perform_request()
except OmnikInverterError:
LOGGER.exception("Failed to connect to the Omnik")
errors["base"] = "cannot_connect"
except Exception as error: # pylint: disable=broad-except
errors["base"] = str(error)
Expand Down

0 comments on commit bc36678

Please sign in to comment.