Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
- loosen method return type restrictions
- add a comment
- handle case where method returns a `Task` that hasn't been started
- fill in a blank warning
- log all `Exception`s in an `AggregateException`
  • Loading branch information
dougbu committed Oct 25, 2018
1 parent 903efbe commit dcbd780
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/GetDocumentInsider/Commands/GetDocumentCommandWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.Extensions.ApiDescription.Tool.Commands
{
Expand Down Expand Up @@ -81,9 +80,8 @@ public static bool TryProcess(GetDocumentCommandContext context, IServiceProvide
Reporter.WriteWarning(Resources.FormatMethodNotFound(methodName, serviceName));
return false;
}
else if (method.ReturnType != typeof(Task))
else if (!typeof(Task).IsAssignableFrom(method.ReturnType))
{
// Do not support Task<T> because we do nothing with the Result.
Reporter.WriteWarning(Resources.FormatMethodReturnTypeUnsupported(
methodName,
serviceName,
Expand All @@ -99,6 +97,7 @@ public static bool TryProcess(GetDocumentCommandContext context, IServiceProvide
return false;
}

// Create the output FileStream last to avoid corrupting an existing file or writing partial data.
var stream = new MemoryStream();
using (var writer = new StreamWriter(stream))
{
Expand All @@ -110,9 +109,10 @@ public static bool TryProcess(GetDocumentCommandContext context, IServiceProvide
return false;
}

if (!resultTask.Wait(TimeSpan.FromMinutes(1)))
var finished = Task.WhenAny(resultTask, Task.Delay(TimeSpan.FromMinutes(1)));
if (!ReferenceEquals(resultTask, finished))
{
Reporter.WriteWarning($"");
Reporter.WriteWarning(Resources.FormatMethodTimedOut(methodName, serviceName, 1));
return false;
}

Expand All @@ -126,9 +126,12 @@ public static bool TryProcess(GetDocumentCommandContext context, IServiceProvide

return true;
}
catch (AggregateException ex)
catch (AggregateException ex) when (ex.InnerException != null)
{
Reporter.WriteWarning(FormatException(ex.InnerException));
foreach (var innerException in ex.Flatten().InnerExceptions)
{
Reporter.WriteWarning(FormatException(innerException));
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit dcbd780

Please sign in to comment.