cve-bin-tool
cve-bin-tool copied to clipboard
aiohttp fails seem to violate quiet mode
- from #1427
FAILED test/test_cli.py::TestCLI::test_quiet_mode - aiohttp.client_exceptions...
When we have a network connection fail it looks like quiet mode breaks (at least, the test does). In the case of the pull request where this occurred it was not a related error, but we should probably fix it properly.
To be more clear on what to do here:
What we want is for aiohttp exceptions to be caught in the code and translated into some sort of (silent) error condition for quiet_mode users. So you probably need a try .. raises
block that then has cve-bin-tool immediately exit with an appropriate error and error number.
Testing will be a bit of a pain: you're trying to duplicate a loss of network in the middle of updating. You can disconnect your network while running tests to try it manually, but you'll likely need to do something with Mock to test your code in a more reproducible way.
- When trying locally, I'm having
requests.exceptions.ConnectionError
instead ofaiohttp.client_exceptions
. - similar to #2382
try/catch
is working as expected. or again am I missing something? @terriko
@Dev-Voldemort This issue was filed in 2021 so I won't be surprised if the message has changed -- we definitely are trying to switch towards using requests more often.
But yes, a try-catch is probably what's needed with the correct error type. And tests to avoid further failures of this type.
I'll make a PR soon after the other one.
does MirrorError: 39
from error_handler sounds like an appropriate error or do I make a new one?
also, how should I go about for the test?
If it's the mirror that's failing and the error will only happen during mirror network issues, yes, that would be fine. If it's maybe something else that failed then go ahead and make a new one to differentiate.
I honestly don't know the best way to write the test. Something with mock
probably?