lxd: proper error classes for container errors
Metadata
Current evaluation
Merged after approval. Refactored LXD container errors into dedicated classes, relocated them to the LXD module, and fixed architecture retrieval error handling. Added corresponding unit tests. Resolves Launchpad bugs #1734233 and #1734235.
Suggested action: —
No scores available.
Issue body
- [x] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)?
- [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [x] If this is a bugfix. Have you checked that there is a bug report open for the issue you are trying to fix on [bug reports](https://bugs.launchpad.net/snapcraft)?
- [x] If this is a new feature. Have you discussed the design on the [forum](https://forum.snapcraft.io)?
- [x] Have you successfully run `./runtests.sh static`?
- [x] Have you successfully run `./runtests.sh unit`?
-----
This PR refactors container errors to have proper classes and moves them into the LXD module. Also errors are moved into a separate unit test. This includes a fix for error handling of and tests for getting the architecture from the container.
This is part of #1705.
Fixes: [LP: #1734233](https://bugs.launchpad.net/snapcraft/+bug/1734233) [LP: #1734235](https://bugs.launchpad.net/snapcraft/+bug/1734235)
The following new tests are affected:
- tests.unit.test_lxd_errors
- To verify the new and updated error classes.
- tests.unit.lxd.test_architecture_*
- To verify failing to get the architecture from the LXD container.
I locally ran the tests:
- `./runtests.sh tests/unit` with unrelated failures in [tests.unit.test_lifecycle.CoreSetupTestCase.test_core_setup_if_docker_env](https://bugs.launchpad.net/snapcraft/+bug/1752576), `tests.unit.test_mangling.TestClearExecstack.test_execstack_clears` and `tests.unit.test_elf`.
- `./runtests.sh tests/integration` with one unrelated failure in [tests.integration.general.test_parser.TestParserWikis](https://bugs.launchpad.net/snapcraft/+bug/1752580)
- `./runtests.sh static`: Everything passed
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| qwen/qwen3.6-35b-a3b | — | — | Merged after approval. Refactored LXD container errors into dedicated classes, relocated them to the LXD module, and fixed architecture retrieval error handling. Added corresponding unit tests. Resolves Launchpad bugs #1734233 and #1734235. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged changes refactoring LXD container errors into dedicated classes within the LXD module. Relocated error handling and unit tests, fixed architecture retrieval error handling, and resolved Launchpad bugs #1734233 and #1734235. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged refactoring of container errors into dedicated classes within the LXD module. Enhanced error handling for architecture retrieval and added corresponding unit tests. Resolves Launchpad bugs #1734233 and #1734235. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1627 lxd: split container classes into different files | snapcraft | merged | Merged refactoring splitting LXD container classes from lxd.py into separate modules. Improves organization, moves Cleanbuilder methods, de-duplicates env vars, and fixes mocking imports. No functional changes. Approved by two reviewers and passed CI. | |
| #1403 lxd: Only remove container if one exists | snapcraft | merged | Merged following two reviewer approvals and passing CI. The update resolves duplicate exceptions during failed LXD container creation by adding a conditional check before attempting container removal. | |
| #1647 lxd: better surfacing of errors | snapcraft | merged | Merged. Resolves duplicate error printing in LXD by having callers return silent errors with proper exit codes, allowing callees to handle message display. Approved and merged after CI validation. | |
| #1762 lxd: delete container only if parts is empty | snapcraft | merged | Merged fix resolving bug 1734145 by updating LXD container cleanup logic to only delete containers when parts are empty. Approved by one reviewer, passed CI checks, and modified two files. | |
| #1644 lxd: fix the push in container builds | snapcraft | merged | Merged pull request fixing LXD container push builds. Approved by one reviewer, the change refactored test cases for better coverage and updated build logic. Review comments highlighted the need for Travis integration and broader testing beyond unit tests. | |
| #1930 lxd: friendly errror with suggestions if network is broken | snapcraft | merged | Merged improvements to LXD network error handling replace raw stack traces with user-friendly messages and troubleshooting hints. The update explicitly catches connection and encoding exceptions, updates tests, and resolves Launchpad bug #1719952. | |
| #1771 lxd: suppress traceback when lxc launch / init fails | snapcraft | merged | Merged to suppress tracebacks when lxc launch or init fails, relying on lxc's native error output. Approved by one reviewer, modifying three files (+35/-15). |