-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repo: catch error updating the package cache #2079
Conversation
snapcraft/internal/repo/_deb.py
Outdated
try: | ||
apt_cache.update(fetch_progress=self.progress, | ||
sources_list=sources_list_file) | ||
except apt.cache.FetchFailedException: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the current exception message? We should consider printing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't assume that there is a message. If there is one, like in the linked bug, the message might look like so:
E:Failed to fetch copy:/home/alan/.cache/snapcraft/stage-packages/apt/a810ed86fa085532f20ab86eb7554a1ff527e7f8f46e49c343abc3d7c4d141ae0c39e374361c05f4561cf2aec6689aac/var/lib/apt/lists/partial/security.ubuntu.com_ubuntu_dists_xenial-security_multiverse_dep11_icons-64x64.tar.gz Hash Sum mismatch, E:Failed to fetch copy:/home/alan/.cache/snapcraft/stage-packages/apt/a810ed86fa085532f20ab86eb7554a1ff527e7f8f46e49c343abc3d7c4d141ae0c39e374361c05f4561cf2aec6689aac/var/lib/apt/lists/partial/gb.archive.ubuntu.com_ubuntu_dists_xenial-backports_main_dep11_icons-64x64.tar.gz Hash Sum mismatch, E:Some index files failed to download. They have been ignored, or old ones used instead.
To my mind this doesn't seem very user-friendly. In the same situation, the printed output before that will have Err http://security.ubuntu.com/ubuntu xenial-security/multiverse DEP-11 128x128 Icons Hash Sum mismatch
at the end, so I'd rather be looking at that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the messages to the error (if they're present). And the index will be cleared if it's a hashsum mismatch (regex) so Snapcraft can continue as normal after that, meaning ideally the error should not be surfacing to the user if that was the issue.
Note that this PR fixes #2029. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 with one small suggestion
snapcraft/internal/repo/_deb.py
Outdated
@@ -54,6 +55,8 @@ | |||
''' | |||
_GEOIP_SERVER = "http://geoip.ubuntu.com/lookup" | |||
_library_list = dict() # type: Dict[str, Set[str]] | |||
_HASHSUM_MISMATCH_PATTERN = re.compile( | |||
r'(E:Failed to fetch copy.+Hash Sum mismatch)+') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably omit the "copy" here, this refers to the internal helper that generated the error and it might change in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks for the review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mvo5 for the assist
./runtests.sh static
?./runtests.sh unit
?This PR handles errors when updating the package cache, such as a hash mismatch or unresolved hostnames. The apt API doesn't distinguish these, so unfortunately we can't be very specific here but need to rely on the output we get before the error is raised.
If the error is a hashsum mismatch, the index will be cleared and Snapcraft will continue.
Fixes: #2029 #2030
Fixes: LP: #1747715
The following tests are added/ modified:
apt.cache.FetchFailedException
is handled as a proper error.I locally ran the tests:
./runtests.sh tests/unit
with unrelated failures in tests.unit.test_lifecycle.CoreSetupTestCase.test_core_setup_if_docker_env,tests.unit.test_mangling.TestClearExecstack.test_execstack_clears
andtests.unit.test_elf
../runtests.sh tests/integration
with one unrelated failure in tests.integration.general.test_parser.TestParserWikis./runtests.sh static
: Everything passedManual test steps:
stages-packages: [appstream]
/etc/apt/sources.list
so that it can't update successfully, such as by adding an invalid URL.