Skip to content

Commit

Permalink
Add a better error message when push times out
Browse files Browse the repository at this point in the history
  • Loading branch information
spadapet committed Mar 31, 2016
1 parent cdcab62 commit 6fc1145
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/NuGet.Clients/NuGet.CommandLine/Commands/PushCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ await PushRunner.Run(
NoSymbols,
Console);
}
catch (TaskCanceledException ex)
{
string timeoutMessage = LocalizedResourceManager.GetString(nameof(NuGetResources.PushCommandTimeoutError));
throw new AggregateException(ex, new Exception(timeoutMessage));
}
catch (Exception ex)
{
if (ex is HttpRequestException && ex.InnerException is WebException)
Expand Down

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

3 changes: 3 additions & 0 deletions src/NuGet.Clients/NuGet.CommandLine/NuGetResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -6076,4 +6076,7 @@ Oluşturma sırasında NuGet'in paketleri indirmesini önlemek için, Visual Stu
<data name="Error_UnableToLocateRestoreTarget" xml:space="preserve">
<value>The folder '{0}' does not contain an msbuild solution, packages.config, or project.json file to restore.</value>
</data>
<data name="PushCommandTimeoutError" xml:space="preserve">
<value>Pushing took too long. You can change the default timeout of 300 seconds by using the -Timeout &lt;seconds&gt; option with the push command.</value>
</data>
</root>
28 changes: 18 additions & 10 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/PushCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Dnx.Runtime.Common.CommandLine;
using NuGet.Commands;
using NuGet.Configuration;
Expand Down Expand Up @@ -66,16 +67,23 @@ public static void Register(CommandLineApplication app, Func<ILogger> getLogger)

PackageSourceProvider sourceProvider = new PackageSourceProvider(XPlatUtility.CreateDefaultSettings());

await PushRunner.Run(
sourceProvider.Settings,
sourceProvider,
packagePath,
sourcePath,
apiKeyValue,
timeoutSeconds,
disableBufferingValue,
noSymbolsValue,
getLogger());
try
{
await PushRunner.Run(
sourceProvider.Settings,
sourceProvider,
packagePath,
sourcePath,
apiKeyValue,
timeoutSeconds,
disableBufferingValue,
noSymbolsValue,
getLogger());
}
catch (TaskCanceledException ex)
{
throw new AggregateException(ex, new Exception(Strings.Push_Timeout_Error));
}

return 0;
});
Expand Down
9 changes: 9 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs

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

3 changes: 3 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,7 @@
<data name="Exclude_Description" xml:space="preserve">
<value>Specifies one or more wildcard patterns to exclude when creating a package.</value>
</data>
<data name="Push_Timeout_Error" xml:space="preserve">
<value>Pushing took too long. You can change the default timeout of 300 seconds by using the --timeout &lt;seconds&gt; option with the push command.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,35 @@ public void PushCommand_PushToServerNoSymbols()
}
}

[Fact]
public void PushCommand_PushTimeoutErrorMessage()
{
using (TestDirectory packageDirectory = TestFileSystemUtility.CreateRandomTestFolder())
using (MockServer server = new MockServer())
{
// Arrange
string packageFileName = Util.CreateTestPackage("testPackage1", "1.1.0", packageDirectory);
server.Get.Add("/push", r => "OK");
server.Put.Add("/push", r =>
{
System.Threading.Thread.Sleep(2000);
return HttpStatusCode.Created;
});
server.Start();

// Act
CommandRunnerResult result = CommandRunner.Run(
Util.GetNuGetExePath(),
Directory.GetCurrentDirectory(),
$"push {packageFileName} -Source {server.Uri}push -Timeout 1",
waitForExit: true);

// Assert
Assert.Equal(1, result.Item1);
Assert.Contains("took too long", result.Item3);
}
}

// Tests that push command can follow redirection correctly.
[Fact]
public void PushCommand_PushToServerFollowRedirection()
Expand Down

0 comments on commit 6fc1145

Please sign in to comment.