Skip to content

Commit

Permalink
ENH: Add information about __cause__ exception in the exception printout
Browse files Browse the repository at this point in the history
Inspired by datalad/datalad-container#267

Before this change

    > datalad -l debug download-url shub://datalad/datalad-container:testhelper
    ...
    download_url(error): /home/yoh/.tmp/datalad_temp_test_container_files0tvyery_/ (file) [AccessFailedError(Failed to establish a new session 1 times. )] [Failed to establish a new session 1 times. ]
    [DEBUG  ] could not perform all requested actions: IncompleteResultsError(Command did not complete successfully. 1 failed:
    [{'action': 'download_url',
      'error_message': 'Failed to establish a new session 1 times. ',
      'exception': Failed to establish a new session 1 times.  [download_url.py:__call__:202,base.py:download:533,shub.py:access:50,shub.py:_resolve_url:39,base.py:fetch:643,shub.py:access:50,base.py:access:174,base.py:_fetch:589,http.py:get_downloader_session:633,http.py:get_downloader_session:618,sessions.py:get:602,sessions.py:request:589,sessions.py:send:703,adapters.py:send:517],
      'exception_traceback': '[download_url.py:__call__:202,base.py:download:533,shub.py:access:50,shub.py:_resolve_url:39,base.py:fetch:643,shub.py:access:50,base.py:access:174,base.py:_fetch:589,http.py:get_downloader_session:633,http.py:get_downloader_session:618,sessions.py:get:602,sessions.py:request:589,sessions.py:send:703,adapters.py:send:517]',
      'message': 'AccessFailedError(Failed to establish a new session 1 times. )',
      'path': '/home/yoh/.tmp/datalad_temp_test_container_files0tvyery_/',
      'status': 'error',
      'type': 'file'}])

so no information about actual problem is provided even in DEBUG output.
With this change we get at least full record containing it:

    [DEBUG  ] could not perform all requested actions: IncompleteResultsError(Command did not complete successfully. 1 failed:
    [{'action': 'download_url',
      'error_message': 'Failed to establish a new session 1 times. ',
      'exception': Failed to establish a new session 1 times.  -caused by- HTTPSConnectionPool(host='singularity-hub.org', port=443): Max retries exceeded with url: /api/container/datalad/datalad-container:testhelper (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1000)'))) [download_url.py:__call__:202,base.py:download:533,shub.py:access:50,shub.py:_resolve_url:39,base.py:fetch:643,shub.py:access:50,base.py:access:174,base.py:_fetch:589,http.py:get_downloader_session:633,http.py:get_downloader_session:618,sessions.py:get:602,sessions.py:request:589,sessions.py:send:703,adapters.py:send:517],
      'exception_traceback': '[download_url.py:__call__:202,base.py:download:533,shub.py:access:50,shub.py:_resolve_url:39,base.py:fetch:643,shub.py:access:50,base.py:access:174,base.py:_fetch:589,http.py:get_downloader_session:633,http.py:get_downloader_session:618,sessions.py:get:602,sessions.py:request:589,sessions.py:send:703,adapters.py:send:517]',
      'message': 'AccessFailedError(Failed to establish a new session 1 times. )',
      'path': '/home/yoh/.tmp/datalad_temp_test_container_files0tvyery_/',
      'status': 'error',
      'type': 'file'}])
  • Loading branch information
yarikoptic committed Aug 29, 2024
1 parent d4ce9ce commit b2da0cf
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions datalad/support/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,6 @@ def format_oneline_tb(exc, tb=None, limit=None, include_str=True):
# startup.
from datalad import cfg

if include_str:
# try exc message else exception type
leading = exc.message or exc.name
out = "{} ".format(leading)
else:
out = ""

if tb is None:
tb = traceback.TracebackException.from_exception(
exc,
Expand All @@ -168,6 +161,15 @@ def format_oneline_tb(exc, tb=None, limit=None, include_str=True):
capture_locals=False,
)

if include_str:
# try exc message else exception type
leading = exc.message or exc.name
out = "{} ".format(leading)
if exc_cause := getattr(tb, '__cause__', None):
out += f'-caused by- {format_exception_with_cause(exc_cause)} '
else:
out = ""

entries = []
entries.extend(tb.stack)
if tb.__cause__:
Expand Down

0 comments on commit b2da0cf

Please sign in to comment.