parallel-ssh icon indicating copy to clipboard operation
parallel-ssh copied to clipboard

Provide a more user friendly string representation of common errors

Open andy-slac opened this issue 4 months ago • 1 comments

For general questions please use the mail group.

Describe the bug AuthenticationError (and maybe other exceptions) is rendered in a confusing way when printed (or converted to string. It looks like:

('Authentication error while connecting to %s:%s - %s - retries %s/%s', 'host.example.com', 22, AuthenticationError('No authentication methods succeeded'), 3, 3)

To Reproduce

Steps to reproduce the behavior:

  1. Example code that produces error:
python -c 'from pssh.clients import SSHClient; SSHClient("localhost", user="_dummy_").run_command("echo")'
  1. Stack trace or error messages.
...
  File ".../site-packages/pssh/clients/base/single.py", line 271, in _auth_retry
    raise AuthenticationError(msg, self.host, self.port, ex, retries, self.num_retries)
pssh.exceptions.AuthenticationError: ('Authentication error while connecting to %s:%s - %s - retries %s/%s', 'localhost', 22, AuthenticationError('No authentication methods succeeded'), 3, 3)

Expected behavior I think it would be better if exception was rendered with all pieces combined like

pssh.exceptions.AuthenticationError: Authentication error while connecting to localhost:22 - AuthenticationError('No authentication methods succeeded') - retries 3/3

Actual behaviour Exception is printed like a tuple.

Additional information

>>> pssh.__version__
'0+untagged.23.g024d798.dirty'
>>> ssh2.__version__
'1.1.1'

andy-slac avatar Sep 02 '25 23:09 andy-slac

Thanks for the interest.

All python exceptions with multiple arguments behave like that when printed. It is not a bug.

try:
    raise ValueError("first arg", "second arg")
except Exception as ex:
    print(ex)

>>> ('first arg', 'second arg')

The library could however provide a more user friendly default string representation of standard errors like AuthenticationError showing the error code and message. That will not change how python prints standard exceptions, which these are.

The developer is free to print or not print any exceptions in any format they wish - the arguments are available on the exception object.

pkittenis avatar Sep 22 '25 15:09 pkittenis