Skip to content

Commit

Permalink
Just log an error when static graph-based restore fails to start.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl committed Oct 10, 2023
1 parent 6ce36a5 commit f18a31c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
46 changes: 18 additions & 28 deletions src/NuGet.Core/NuGet.Build.Tasks/StaticGraphRestoreTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,30 @@ public override bool Execute()
try
{
process.Start();
}
catch (Exception e)
{
Log.LogErrorFromResources(nameof(Strings.Error_StaticGraphRestoreFailedToStart), e.Message);

process.BeginOutputReadLine();
process.BeginErrorReadLine();

if (SerializeGlobalProperties)
{
using var writer = new BinaryWriter(process.StandardInput.BaseStream, Encoding.UTF8, leaveOpen: true);

WriteGlobalProperties(writer, globalProperties);
}
return false;
}
finally
{
process.StandardInput.Close();

Console.InputEncoding = previousConsoleInputEncoding;
}

process.BeginOutputReadLine();
process.BeginErrorReadLine();

if (SerializeGlobalProperties)
{
using var writer = new BinaryWriter(process.StandardInput.BaseStream, Encoding.UTF8, leaveOpen: true);

WriteGlobalProperties(writer, globalProperties);
}

process.StandardInput.Close();

semaphore.Wait(_cancellationTokenSource.Token);

if (!process.HasExited)
Expand Down Expand Up @@ -224,23 +230,7 @@ e is OperationCanceledException
internal string GetCommandLineArguments(Dictionary<string, string> globalProperties)
{
// First get the command-line arguments including the global properties
string commandLineArguments = CreateArgumentString(EnumerateCommandLineArguments(SerializeGlobalProperties ? null : globalProperties));

if (SerializeGlobalProperties)
{
return commandLineArguments;
}

// If the command-line arguments exceed the supported length, set the flag to serialize the global properties to the standard input stream get the
// arguments again without the global properties.
if (commandLineArguments.Length > 8000)
{
SerializeGlobalProperties = true;

commandLineArguments = CreateArgumentString(EnumerateCommandLineArguments(globalProperties: null));
}

return commandLineArguments;
return CreateArgumentString(EnumerateCommandLineArguments(SerializeGlobalProperties ? null : globalProperties));

IEnumerable<string> EnumerateCommandLineArguments(Dictionary<string, string> globalProperties)
{
Expand Down
9 changes: 9 additions & 0 deletions src/NuGet.Core/NuGet.Build.Tasks/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/NuGet.Core/NuGet.Build.Tasks/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,8 @@
<value>An error occurred parsing command-line arguments in static graph-based restore as the first integer read, {0}, is not an allowable value. Please file an issue at https://github.com/NuGet/Home</value>
<comment>0 - The value of the first integer read from the stream</comment>
</data>
<data name="Error_StaticGraphRestoreFailedToStart" xml:space="preserve">
<value>An error occurred starting static graph-based restore. {0}. Please file an issue at https://github.com/NuGet/Home</value>
<comment>0 - The exception message</comment>
</data>
</root>

0 comments on commit f18a31c

Please sign in to comment.