feat: improve logging on snap error#162
Merged
james-garner-canonical merged 9 commits intocanonical:mainfrom Jun 16, 2025
Merged
Conversation
benhoyt
reviewed
Jun 8, 2025
Co-authored-by: Ben Hoyt <benhoyt@gmail.com>
benhoyt
approved these changes
Jun 13, 2025
f89e03b
into
canonical:main
13 of 14 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a
SnapErroris raised after asnapcommand errors (raising aCalledProcessError), the error does not currently contain the process'sstderr. Additionally, the failure information may not be present instdoutorstderr, but may instead have been logged to the journal. This PR updates the 6 call sites where aCalledProcessErroris converted to aSnapErroras follows:subprocesscall is updated to always capturestdoutandstderrso that these are available in theCalledProcessErrorCalledProcessErrorare passed to a new constructor forSnapErrorSnapError._from_called_process_errorextends the provided message withstdoutandstderrfrom theCalledProcessError, and attempts to extend it further with the last 20 entries from the journal from thesnapdunit -- if this fails, the failure is appended to the message insteadThe unit tests have been updated due to the changes to the
subprocesscalls. The functional change is exercised in an integration test, which has been updated to be more strict (previously it could pass even if the expected error wasn't raised), and to check that the logs have been retrieved successfully.Fixes: #136
This is an example of the new error output (captured by forcing re-raising the exception caught in the integration test):