irods / python-irodsclient

A Python API for iRODS
Other
62 stars 73 forks source link

avoid confusing SyntaxError message when connections fail #641

Open d-w-moore opened 1 month ago

d-w-moore commented 1 month ago
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/site-packages/irods/session.py", line 326, in server_version
    return tuple(ast.literal_eval(reported_vsn))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/ast.py", line 64, in literal_eval
    node_or_string = parse(node_or_string.lstrip(" \t"), mode='eval')
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.10/x64/lib/python3.11/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<unknown>", line 0

SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

The above excerpt (the beginning of a stack trace) was obtained from a case of failing to contact the server. This part need not even be printed , and would not be except that normal program flow sends us into the raising of an exception , just because the user has not defined the environment variable PYTHON_IRODSCLIENT_REPORTED_SERVER_VERSION. This can be handled better with a simple if/then so that we don't see the Syntax Error.

Python error dumps are complicated enough, let's do better in the future.