-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Process.Start() failure should include path #39928
Comments
Tagging subscribers to this area: @eiriktsarpalis |
Likely something like @@ -613,7 +613,9 @@ private unsafe bool StartWithCreateProcess(ProcessStartInfo startInfo)
{
throw new Win32Exception(errorCode, SR.InvalidApplication);
}
- throw new Win32Exception(errorCode);
+
+ string msg = SR.Format(SR.FailedToStartFileDirectory, startInfo.FileName, startInfo.WorkingDirectory, new Win32Exception(errorCode).Message);
+ throw new Win32Exception(errorCode, msg); and + <data name="FailedToStartFileDirectory" xml:space="preserve">
+ <value>Failed to start '{0}' with working directory '{1}'. {2}</value>
+ </data> |
dotnet/msbuild#5355 is another example where this would be useful. |
Sure. Will use some of the time i reserved for Hacktobest and try to implement this. |
Sounds great to me - assigned to you. |
I started to have a look at the code and was wondering how to solve this i an way that ensures that we always provide the information about file and working directory. A sample of such a possible solution (quick and dirty) can be found at https://github.com/batzen/runtime/tree/issues/39928 |
I’m not able to look at the code right now, but is a diff like the one I pasted above not possible? |
Don't know how to produce a diff here. But the could would be like: public bool Start()
{
Close();
ProcessStartInfo startInfo = StartInfo;
if (startInfo.FileName.Length == 0)
{
throw new InvalidOperationException(SR.FileNameMissing);
}
try
{
if (startInfo.StandardInputEncoding != null && !startInfo.RedirectStandardInput)
{
throw new InvalidOperationException(SR.StandardInputEncodingNotAllowed);
}
if (startInfo.StandardOutputEncoding != null && !startInfo.RedirectStandardOutput)
{
throw new InvalidOperationException(SR.StandardOutputEncodingNotAllowed);
}
if (startInfo.StandardErrorEncoding != null && !startInfo.RedirectStandardError)
{
throw new InvalidOperationException(SR.StandardErrorEncodingNotAllowed);
}
if (!string.IsNullOrEmpty(startInfo.Arguments) && startInfo.ArgumentList.Count > 0)
{
throw new InvalidOperationException(SR.ArgumentAndArgumentListInitialized);
}
//Cannot start a new process and store its handle if the object has been disposed, since finalization has been suppressed.
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
}
SerializationGuard.ThrowIfDeserializationInProgress("AllowProcessCreation", ref s_cachedSerializationSwitch);
return StartCore(startInfo);
}
catch (Exception exception)
{
string workingDirectory = !string.IsNullOrWhiteSpace(startInfo.WorkingDirectory) ? startInfo.WorkingDirectory : Directory.GetCurrentDirectory();
string msg = SR.Format(SR.FailedToStartFileDirectory, startInfo.FileName, workingDirectory);
throw new ProcessStartException(msg, startInfo, exception);
}
}
[Serializable]
public class ProcessStartException : Exception
{
public ProcessStartException()
{
}
public ProcessStartException(string message)
: base(message)
{
}
public ProcessStartException(string message, ProcessStartInfo startInfo)
: base(message)
{
this.StartInfo = startInfo;
}
public ProcessStartException(string message, Exception inner)
: base(message, inner)
{
}
public ProcessStartException(string message, ProcessStartInfo startInfo, Exception inner)
: base(message, inner)
{
this.StartInfo = startInfo;
}
protected ProcessStartException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
[field: NonSerialized]
public ProcessStartInfo StartInfo { get; private set; }
} |
Can’t you just adjust the existing message as I have shown above? |
Of course. |
Sure, let's see how that works out in your testing. BTW, new API (like your BTW, this ugliness |
@batzen did you have success? |
Not yet. Had get some other OSS stuff done first. |
@batzen have you made any progress on this? do you need some help? |
I had some massive issues with the build scripts.
I sorted all those out by "fixing" the build scripts on my machine. When i am done with my changes and the PR i will try to write all that down and create a separate issue for that. According to my progress: Sorry for the long delays but i am very busy at work as we are porting 1 million lines of code from vb6 to c# and that's a lot of work. ;-) |
@batzen hmm, the steps I normally use for libraries work are essentially these
I'm not sure about the other two issues unfortunately. I do most of the build on the command line, in a regular command prompt (not a developer prompt) although I wouldn't expect that part to matter. |
@adamsitnik @danmosemsft I could need some help. As soon as that mystery is solved i can finish my changes. ;-) |
@batzen our tests usually don't verify the exception string. We verify the exception type, and if looking for a particular value in the string (the path in this case, presumably) we just use this pattern |
When a process cannot be started, it would be useful for the exception to include the ProcessStartInfo or equivalent.
For example, I got this in the VS output window - I assume it's missing a certain dotnet.exe but I don't know which. I've encountered this in other situations.
We already special case two codes
https://github.com/danmosemsft/runtime/blob/58e6ab1054b8809b3c91fcd75d1dbfff559e9573/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs#L612-L616
We would special case ERROR_DIRECTORY, ERROR_FILE_NOT_FOUND, ERROR_INVALID_PARAMETER, ERROR_INVALID_NAME, ERROR_PATH_NOT_FOUND, and ERROR_ACCESS_DENIED and for those include psi.FileName and psi.WorkingDirectory in the message. (Or just do it in all cases) and analogous in Unix:
runtime/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs
Line 528 in 1923bba
The text was updated successfully, but these errors were encountered: