NoWorkingMirrorError swallows error messages
See original GitHub issueDescription of issue:
When tuf raises a NoWorkingMirrorError, it displays the list of URLs with the corresponding exception classes, but the error message of each exception is lost.
Current behavior:
I got the following error in some logs:
tuf.exceptions.NoWorkingMirrorError: No working mirror was found:
'xxx': ReplayedMetadataError()
You can reproduce the issue easily with the following script:
import tuf.exceptions
error = tuf.exceptions.ReplayedMetadataError('myrole', '1.2.3', '1.2.1')
print(str(error))
mirror_error = tuf.exceptions.NoWorkingMirrorError({'myurl': error})
print(str(mirror_error))
Which outputs:
Downloaded 'myrole' is older ('1.2.3') than the version currently installed ('1.2.1').
No working mirror was found:
'': ReplayedMetadataError()
Expected behavior:
I want to get the actual content of ReplayedMetadataError.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
NoWorkingMirrorError swallows error messages #857 - GitHub
Description of issue: When tuf raises a NoWorkingMirrorError, it displays the list of URLs with the corresponding exception classes, ...
Read more >Why do programmers sometimes silently swallow exceptions?
I suppose I really should write out some sort of error message, but if I've already successfully read the data, it seems superfluous....
Read more >Error hiding - Wikipedia
In computer programming, error hiding (or error swallowing) is the practice of catching an error or exception, and then continuing without logging, ...
Read more >Do not swallow exceptions - Semicolon & Sons
Do not swallow exceptions. This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job ... Another example...
Read more >Powershell swallows error output - Visual Studio Feedback
For a Powershell task version 2.* with the following inline script: $PSVersionTable.PSVersion cmd /c "echo STDOUT & echo STDERR 1>&2 & sleep 1...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That actually won’t fix the missing information in the logs, in part because
updater
’s loggers don’t callstr()
onNoWorkingMirrorError
, so changingNoWorkingMirrorError.__str__()
won’t fix it. Example logging here.This problem is basically a result of some fancy exception classes that have calculated error messages produced by
__str__()
, but no__repr__()
methods. When those (ReplayedMetadataError
,BadHashError
, some others) are put in aNoWorkingMirrorError
, the calculated messages don’t show up in the logs. Others, likeBadVersionNumberError
, still show up fine in logs (or a script like the above) when they’re put into aNoWorkingMirrorError
.The easiest fix here is probably one of these options:
NoWorkingMirrorError.__str__()
as @adityasaky suggests, and also change all thelogger.error()
calls to both mention the particular exception types and then callstr()
(since otherwise you’d lose the individual exception types in the logs)__repr__()
method toReplayedMetadataError
and similar exceptionsI think the pythonic answer is probably 2, since
repr()
is intended for this kind of debugging.Ah, @therve is one of us at Datadog, thanks for helping out 😃