question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NoWorkingMirrorError swallows error messages

See original GitHub issue

Description 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
awwadcommented, Apr 17, 2019

That actually won’t fix the missing information in the logs, in part because updater’s loggers don’t call str() on NoWorkingMirrorError, so changing NoWorkingMirrorError.__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 a NoWorkingMirrorError, the calculated messages don’t show up in the logs. Others, like BadVersionNumberError, still show up fine in logs (or a script like the above) when they’re put into a NoWorkingMirrorError.

The easiest fix here is probably one of these options:

  1. change NoWorkingMirrorError.__str__() as @adityasaky suggests, and also change all the logger.error() calls to both mention the particular exception types and then call str() (since otherwise you’d lose the individual exception types in the logs)
  2. or add a __repr__() method to ReplayedMetadataError and similar exceptions

I think the pythonic answer is probably 2, since repr() is intended for this kind of debugging.

1reaction
trishankatdatadogcommented, Apr 17, 2019

Ah, @therve is one of us at Datadog, thanks for helping out 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found