jedie / inverter-connect

Get information from Deye Microinverter
https://pypi.org/project/inverter-connect/
GNU General Public License v3.0
27 stars 9 forks source link

Show last exception only #32

Closed CarstenGrohmann closed 1 year ago

CarstenGrohmann commented 1 year ago

I tried to query my inverter when it was powered off.

This results in a stack trace with two exceptions, as shown in the following example.

From my user perspective, the second exception ReadTimeout: Get no response from inverter: timed out is enough information. The stack trace and the first exception TimeoutError: timed out is not necessary and should be hidden by default or only shown when debug is enabled.

What do you think about reducing the output in this situation?

# ./cli.py print-at-commands inverter NTPTM NTPSER NTPRF NTPEN

+ inverter-connect/.venv-app/bin/inverter_app print-at-commands inverter NTPTM NTPSER NTPRF NTPEN

inverter v0.4.0
INFO:inverter.connection:Connect to inverter:48899...
Traceback (most recent call last):
  File "inverter-connect/inverter/connection.py", line 229, in recv_command
    data = self.sock.recv(buffer_size)
TimeoutError: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "inverter-connect/.venv-app/bin/inverter_app", line 8, in <module>
    sys.exit(main())
  File "inverter-connect/inverter/__main__.py", line 11, in main
    cli_app.main()
  File "inverter-connect/inverter/cli/cli_app.py", line 422, in main
    cli()
  File "inverter-connect/.venv-app/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "inverter-connect/.venv-app/lib/python3.10/site-packages/rich_click/rich_group.py", line 21, in main
    rv = super().main(*args, standalone_mode=False, **kwargs)
  File "inverter-connect/.venv-app/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "inverter-connect/.venv-app/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "inverter-connect/.venv-app/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "inverter-connect/.venv-app/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "inverter-connect/inverter/cli/cli_app.py", line 209, in print_at_commands
    with InverterSock(config) as inv_sock:
  File "inverter-connect/inverter/connection.py", line 208, in __enter__
    self.inverter_info = self.init_inventer()
  File "inverter-connect/inverter/connection.py", line 274, in init_inventer
    data = self.recv_command(command=self.config.init_cmd)
  File "inverter-connect/inverter/connection.py", line 231, in recv_command
    raise ReadTimeout(f'Get no response from {self.config.host}: {err}')
inverter.exceptions.ReadTimeout: Get no response from inverter: timed out

Regards, Carsten

jedie commented 1 year ago

From my user perspective, the second exception ReadTimeout: Get no response from inverter: timed out is enough information. The stack trace and the first exception TimeoutError: timed out is not necessary and should be hidden by default or only shown when debug is enabled.

This is the normal Python Traceback behavior.

I changed how common connection errors are handles and cleaned the output with https://github.com/jedie/inverter-connect/pull/33

CarstenGrohmann commented 1 year ago

Thank you for implementing this change:

INFO:inverter.connection:Connect to inverter:48899...
Get no response from inverter: timed out