Skip to content

Commit

Permalink
ENH: Add -caused by- into format_short
Browse files Browse the repository at this point in the history
It is necessary for various interface points to actually provide
information about exception.  E.g. if used in conjunction with

- datalad#7648
- /home/yoh/proj/misc/AnnexRemote

then we would not only obtain although quite loaded but meaningful error
result rendering:

    download_url(error): /tmp/ (file) [AccessFailedError(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)')))] [Failed to establish a new session 1 times. ]

we would also make git-annex report the reason!:

    ❯ git annex  addurl shub://datalad/datalad-container:testhelper
    addurl shub://datalad/datalad-container:testhelper
      AccessFailedError(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)')))
    failed
    addurl: 1 failed
  • Loading branch information
yarikoptic committed Aug 29, 2024
1 parent b2da0cf commit a154aff
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion datalad/support/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ def format_short(self):
-------
str
"""
return self.name + '(' + self.message + ')'
s = self.name + '(' + self.message + ')'
if exc_cause := getattr(self.tb, '__cause__', None):
s += f' -caused by- {format_exception_with_cause(exc_cause)}'
return s

def format_with_cause(self):
"""Returns a representation of the original exception including the
Expand Down

0 comments on commit a154aff

Please sign in to comment.