Skip to content

Conversation

@HofmeisterAn
Copy link
Collaborator

What does this PR do?

This PR adds an ExecResult extension method ThrowOnFailure which throws an exception if a command run inside a container fails. This makes it easier to fail fast without having to manually check the result every time.

Why is it important?

-

Related issues

@HofmeisterAn HofmeisterAn added the enhancement New feature or request label May 17, 2025
@netlify
Copy link

netlify bot commented May 17, 2025

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit 063c4e4
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/682859117584900008b40bbd
😎 Deploy Preview https://deploy-preview-1448--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.

@HofmeisterAn HofmeisterAn changed the title feat: Add ExecResult extension ThrowOnFailure feat: Add Task<ExecResult> extension method ThrowOnFailure May 17, 2025
@HofmeisterAn HofmeisterAn merged commit a668d34 into develop May 17, 2025
133 checks passed
@HofmeisterAn HofmeisterAn deleted the feature/add-exec-result-extensions-throw-on-failure branch May 17, 2025 10:05
Copy link

@riezebosch riezebosch left a comment

Choose a reason for hiding this comment

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

nice that you added my suggestion!

/// <exception cref="ExecFailedException">Thrown if the exit code is not in the list of success exit codes.</exception>
public static async Task<ExecResult> ThrowOnFailure(this Task<ExecResult> execTask, params long[] successExitCodes)
{
successExitCodes = successExitCodes == null || successExitCodes.Length == 0 ? new long[] { 0 } : successExitCodes;

Choose a reason for hiding this comment

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

could've used successExitCodes?.Any() here


exceptionInfo.AppendLine();
exceptionInfo.AppendLine(" Stderr: ");
exceptionInfo.Append(string.Join(Environment.NewLine, stderrLines));

Choose a reason for hiding this comment

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

why combine StringBuilder with linq?

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.

[Enhancement]: extension method to throw on errors for the MsSqlContainer

3 participants