Skip to content

feat: Improve image build failure messages#1700

Merged
HofmeisterAn merged 2 commits into
developfrom
feature/include-image-build-error-message
Jun 12, 2026
Merged

feat: Improve image build failure messages#1700
HofmeisterAn merged 2 commits into
developfrom
feature/include-image-build-error-message

Conversation

@HofmeisterAn

@HofmeisterAn HofmeisterAn commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

This PR adds additional error details when an image build fails.

Previously, the error message was very generic and did not provide any information about the underlying cause of the failure. To diagnose image build issues, developers had to inspect the console output, which is not always obvious. In addition, .NET console messages can be difficult to locate, especially for a library that is primarily executed in test environments.

With this change, the image build error details are included directly in the exception. A failed image build will now throw an ImageBuildFailedException containing the relevant error information, making failures easier to diagnose and troubleshoot.

Why is it important?

-

Related issues

Summary by CodeRabbit

  • Bug Fixes

    • Docker image build failures now surface detailed diagnostic errors (captured during build) instead of generic messages.
  • New Features

    • Build error details are collected and included in the reported failure to aid troubleshooting.
  • Tests

    • Added a unit test that verifies detailed error reporting on image build failure.
  • Chores

    • Test assets updated to include a failing build scenario and adjusted ignore patterns.

@HofmeisterAn HofmeisterAn added the enhancement New feature or request label Jun 12, 2026
@netlify

netlify Bot commented Jun 12, 2026

Copy link
Copy Markdown

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit 9fd773a
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/6a2c169db26d920008febd4c
😎 Deploy Preview https://deploy-preview-1700--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 888a75c9-905e-4d67-8a58-7a08c15f99f6

📥 Commits

Reviewing files that changed from the base of the PR and between d13ef1b and 9fd773a.

📒 Files selected for processing (1)
  • tests/Testcontainers.Tests/Assets/.dockerignore
✅ Files skipped from review due to trivial changes (1)
  • tests/Testcontainers.Tests/Assets/.dockerignore

Walkthrough

TraceProgress now accumulates Docker JSON errors; ImageBuildFailedException formats image+error details; DockerImageOperations creates local TraceProgress instances and throws ImageBuildFailedException with collected errors on build failure. Tests and a failing Dockerfile verify the new error message content.

Changes

Docker Build Failure Error Reporting

Layer / File(s) Summary
Error tracking in TraceProgress
src/Testcontainers/Clients/TraceProgress.cs
TraceProgress adds a thread-safe ConcurrentQueue<JSONError> and exposes errors via an Errors property. Report enqueues value.Error when present. Progress logging now requires value.Progress.Current to be present before computing percentages.
ImageBuildFailedException definition
src/Testcontainers/Images/ImageBuildFailedException.cs
New sealed exception ImageBuildFailedException(IImage image, IEnumerable<JSONError> errors) builds a formatted message including the image full name and filtered build error messages separated by newlines.
DockerImageOperations integration
src/Testcontainers/Clients/DockerImageOperations.cs
Constructor no longer stores an instance-level _traceProgress. CreateAsync and BuildAsync create local TraceProgress instances tied to the current Logger and pass them to Docker client calls. On build failure the code throws ImageBuildFailedException(image, traceProgress.Errors) instead of a generic InvalidOperationException.
Test validation for error reporting
tests/Testcontainers.Tests/Assets/buildFailure/Dockerfile, tests/Testcontainers.Tests/Assets/.dockerignore, tests/Testcontainers.Tests/Unit/Images/ImageFromDockerfileTest.cs
Adds a failing Dockerfile (pinned Alpine + nonexistent command), updates .dockerignore to ignore the asset, and adds a test asserting ImageBuildFailedException is thrown with a message containing the image name, creation failure text, and the detailed shell error output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit nibbles through the log,
Errors gathered, cleared the fog.
Builds once silent now explain,
Each failed step spelled out plainly.
Hop—problem found, and fixed again.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: improving image build failure messages with better error details.
Description check ✅ Passed The PR description covers the main changes, motivation, and linked issue; the optional sections are appropriately omitted.
Linked Issues check ✅ Passed The PR fully addresses issue #1695 by providing detailed error information in ImageBuildFailedException instead of generic messages.
Out of Scope Changes check ✅ Passed All changes are directly related to improving image build failure messages; no out-of-scope modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/include-image-build-error-message

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
tests/Testcontainers.Tests/Unit/Images/ImageFromDockerfileTest.cs (1)

231-247: ⚡ Quick win

Test assumes specific Docker error message format.

The assertion on line 246 expects the exact error message "The command '/bin/sh -c command-that-does-not-exist' returned a non-zero code: 127". While this validates the error collection mechanism, it couples the test to Docker's error message format, which could change across Docker versions or container runtimes (e.g., Podman).

Consider whether a more flexible assertion (e.g., Contains("command-that-does-not-exist") and Contains("127")) would provide sufficient validation while being more resilient to Docker engine variations.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Testcontainers.Tests/Unit/Images/ImageFromDockerfileTest.cs` around
lines 231 - 247, The test BuildFailureIncludesDetailedErrorMessage in
ImageFromDockerfileTest is coupled to a specific Docker error string; update the
assertions to be resilient by checking presence of the failing command and exit
code rather than the full Docker message — e.g., assert that exception.Message
Contains "command-that-does-not-exist" and Contains "127" (keep the existing
Assert.StartsWith/Contains for the general framing), referencing the
ImageFromDockerfileBuilder.CreateAsync invocation and the
ImageBuildFailedException to locate the test.
src/Testcontainers/Images/ImageBuildFailedException.cs (1)

26-43: 💤 Low value

Consider removing trailing space in error section label.

Line 38 includes a trailing space in " Error: " before the newline. While not a functional issue, removing it would improve consistency.

♻️ Proposed formatting adjustment
-        exceptionInfo.AppendLine("  Error: ");
+        exceptionInfo.AppendLine("  Error:");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Testcontainers/Images/ImageBuildFailedException.cs` around lines 26 - 43,
The CreateMessage method in ImageBuildFailedException.cs appends an error
section label with a trailing space ("  Error: "); remove the trailing space so
the label is "  Error:" to keep formatting consistent; update the call to
exceptionInfo.AppendLine in CreateMessage (the line that currently uses " 
Error: ") to use the trimmed label and run tests/formatting to ensure no other
spacing expectations rely on the extra space.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/Testcontainers/Images/ImageBuildFailedException.cs`:
- Around line 26-43: The CreateMessage method in ImageBuildFailedException.cs
appends an error section label with a trailing space ("  Error: "); remove the
trailing space so the label is "  Error:" to keep formatting consistent; update
the call to exceptionInfo.AppendLine in CreateMessage (the line that currently
uses "  Error: ") to use the trimmed label and run tests/formatting to ensure no
other spacing expectations rely on the extra space.

In `@tests/Testcontainers.Tests/Unit/Images/ImageFromDockerfileTest.cs`:
- Around line 231-247: The test BuildFailureIncludesDetailedErrorMessage in
ImageFromDockerfileTest is coupled to a specific Docker error string; update the
assertions to be resilient by checking presence of the failing command and exit
code rather than the full Docker message — e.g., assert that exception.Message
Contains "command-that-does-not-exist" and Contains "127" (keep the existing
Assert.StartsWith/Contains for the general framing), referencing the
ImageFromDockerfileBuilder.CreateAsync invocation and the
ImageBuildFailedException to locate the test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 31b8c739-f38b-4077-ae46-997bf1c1da8d

📥 Commits

Reviewing files that changed from the base of the PR and between c7e61d6 and d13ef1b.

📒 Files selected for processing (5)
  • src/Testcontainers/Clients/DockerImageOperations.cs
  • src/Testcontainers/Clients/TraceProgress.cs
  • src/Testcontainers/Images/ImageBuildFailedException.cs
  • tests/Testcontainers.Tests/Assets/buildFailure/Dockerfile
  • tests/Testcontainers.Tests/Unit/Images/ImageFromDockerfileTest.cs

@HofmeisterAn
HofmeisterAn merged commit a4c0b58 into develop Jun 12, 2026
84 checks passed
@HofmeisterAn
HofmeisterAn deleted the feature/include-image-build-error-message branch June 12, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: The error message "Docker image xxx has not been created." is totally useless

1 participant