You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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(ProcessExceptionex){// 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.
The text was updated successfully, but these errors were encountered:
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
changed the title
Make 'ProcessException.Process' public
Make available exit code of failed process (ProcessException.Process)
Feb 21, 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
Alternative
I use reflection to pull out exit code of the process from
ProcessException
.The text was updated successfully, but these errors were encountered: