Follow-up: improve Docker daemon image-build errors#65
Follow-up: improve Docker daemon image-build errors#65aniketmaurya wants to merge 1 commit intomainfrom
Conversation
π WalkthroughWalkthroughThis change enhances Docker error reporting by introducing a new diagnostic helper method that provides context-aware error messages for various Docker failure modes (missing, daemon unreachable, permissions). The method replaces hard-coded error messages across multiple build methods with richer error objects. Changes
Estimated code review effortπ― 3 (Moderate) | β±οΈ ~25 minutes Poem
π₯ Pre-merge checks | β 3β Passed checks (3 passed)
βοΈ Tip: You can configure your own custom pre-merge checks in the settings. β¨ Finishing Touchesπ Generate docstrings
π§ͺ Generate unit tests (beta)
π Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can use your project's `ruff` configuration to improve the quality of Python code reviews.Add a Ruff configuration file to your project to customize how CodeRabbit runs |
There was a problem hiding this comment.
π§Ή Nitpick comments (1)
tests/test_build.py (1)
36-70: Good test coverage for the primary Docker diagnostic scenarios.The tests correctly validate:
- Missing Docker binary (
shutil.whichreturnsNone)- Daemon unreachable (connection error in stderr)
Consider adding a test for the permission-denied path (lines 148-151 in
docker_requirement_error) to ensure complete coverage of the diagnostic branches:def test_docker_requirement_error_when_permission_denied( self, tmp_path: Path ) -> None: builder = ImageBuilder(cache_dir=tmp_path / "images") with ( patch("smolvm.build.shutil.which", return_value="/usr/bin/docker"), patch("smolvm.build.subprocess.run") as mock_run, ): mock_run.side_effect = subprocess.CalledProcessError( 1, ["docker", "info"], stderr="permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock", ) error = builder.docker_requirement_error() assert "cannot access the Docker daemon socket" in str(error)π€ Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/test_build.py` around lines 36 - 70, Add a new unit test in tests/test_build.py that exercises the permission-denied branch of ImageBuilder.docker_requirement_error: create an ImageBuilder(cache_dir=tmp_path/"images"), patch "smolvm.build.shutil.which" to return a docker path and patch "smolvm.build.subprocess.run" to raise subprocess.CalledProcessError(1, ["docker","info"], stderr="permission denied ... unix:///var/run/docker.sock"), call builder.docker_requirement_error(), and assert the returned error message contains the expected phrase (e.g. "cannot access the Docker daemon socket") to cover the permission-denied diagnostic branch.
π€ Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/test_build.py`:
- Around line 36-70: Add a new unit test in tests/test_build.py that exercises
the permission-denied branch of ImageBuilder.docker_requirement_error: create an
ImageBuilder(cache_dir=tmp_path/"images"), patch "smolvm.build.shutil.which" to
return a docker path and patch "smolvm.build.subprocess.run" to raise
subprocess.CalledProcessError(1, ["docker","info"], stderr="permission denied
... unix:///var/run/docker.sock"), call builder.docker_requirement_error(), and
assert the returned error message contains the expected phrase (e.g. "cannot
access the Docker daemon socket") to cover the permission-denied diagnostic
branch.
βΉοΈ Review info
βοΈ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9ad8c547-318a-4d57-8aec-96bb1dd6a52b
π Files selected for processing (2)
src/smolvm/build.pytests/test_build.py
Motivation
Docker is required to build imageserror even when Docker is installed but the daemon is not reachable, which provides poor guidance for common failures.Description
ImageBuilder.check_dockerto usedocker infoso the check verifies the daemon is reachable as well as the client binary being present (src/smolvm/build.py).ImageBuilder.docker_requirement_error()to produce richer, actionableImageErrormessages for three cases: Docker not installed, Docker daemon unreachable (include original Docker error text), and permission/socket-access issues (src/smolvm/build.py).ImageErrorraises in the image build entry points to call the new diagnostic helper so all image-build paths (build_alpine_ssh,build_alpine_ssh_key,build_debian_ssh_key, and similar) surface the improved message (src/smolvm/build.py).tests/test_build.py).Testing
ruff check src/smolvm/build.py tests/test_build.pyand it passed.PYTHONPATH=src pytest tests/test_build.pyand all tests passed (7 passed).pytest tests/test_build.pywithoutPYTHONPATH=srcfails in this environment due to the package not being installed into the interpreter path (import error), which is unrelated to the code changes.Codex Task
Summary by CodeRabbit
New Features
Tests