Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make available exit code of failed process (ProcessException.Process) #875

Closed
satano opened this issue Feb 18, 2022 · 1 comment · Fixed by #1068
Closed

Make available exit code of failed process (ProcessException.Process) #875

satano opened this issue Feb 18, 2022 · 1 comment · Fixed by #1068

Comments

@satano
Copy link

satano commented Feb 18, 2022

Description

When I use custom tool lightway integration, the only way how to handle errors in process is catching ProcessException. But just to catch the exception is often not enough. I would like to have some logic and decide, if there is really a problem, or not. The minimum is to have the value of process exit code and decide what to do. Because some exit codes are not real errors and can be handled and the build can continue.

Usage Example

[PathExecutable("dotnet-affected")]
readonly Tool DotnetAffected;

// In target execution:
try
{
    DotnetAffected(args);
}
catch (ProcessException ex)
{
    // We use this kind of logic.
    // 'GetProcessExitCode()' is our extension method which uses reflection to pull out exit code.
    if (ex.GetProcessExitCode() == SomeOkExitCode)
    {
        // I can handle this.
    }
    else
    {
        // Anything else is something I cannot handle.
        throw;
    }
}

Alternative

I use reflection to pull out exit code of the process from ProcessException.

@satano
Copy link
Author

satano commented Feb 18, 2022

It would be useful to have exit codes available even for built-in tools. For example, I wanted to change my previous example, so it is not using [PathExecutable("dotnet-affected")], but use dotnet tool run. The reason is, this way, we can have that tool installed locally in project. Using PathExecutable, the tool iteself must be installed globally.

So I created tool manifest in the project, installed the tool I want and in the Nuke's target run:

DotNet("tool run dotnet-affected")

When this command returns non-zero exit code, it again fails with ProcessException. But this time, I cannot get that exit code even with reflection, because it is lost already. I got just another exception InvalidOperationException: No process is associated with this object..

@satano satano changed the title Make 'ProcessException.Process' public Make available exit code of failed process (ProcessException.Process) Feb 21, 2022
@matkoch matkoch linked a pull request Dec 12, 2022 that will close this issue
3 tasks
@matkoch matkoch closed this as completed Dec 12, 2022
@matkoch matkoch added this to the v6.2.2 milestone Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants