Make AngularCliBuilder provide better information about timeouts

This commit is contained in:
Steve Sanderson
2017-11-22 15:06:45 +00:00
parent 50ba6114ee
commit 18140929e7

View File

@@ -39,7 +39,7 @@ namespace Microsoft.AspNetCore.SpaServices.AngularCli
} }
/// <inheritdoc /> /// <inheritdoc />
public Task Build(ISpaBuilder spaBuilder) public async Task Build(ISpaBuilder spaBuilder)
{ {
var sourcePath = spaBuilder.Options.SourcePath; var sourcePath = spaBuilder.Options.SourcePath;
if (string.IsNullOrEmpty(sourcePath)) if (string.IsNullOrEmpty(sourcePath))
@@ -57,18 +57,27 @@ namespace Microsoft.AspNetCore.SpaServices.AngularCli
null); null);
npmScriptRunner.AttachToLogger(logger); npmScriptRunner.AttachToLogger(logger);
using (var stdOutReader = new EventedStreamStringReader(npmScriptRunner.StdOut))
using (var stdErrReader = new EventedStreamStringReader(npmScriptRunner.StdErr)) using (var stdErrReader = new EventedStreamStringReader(npmScriptRunner.StdErr))
{ {
try try
{ {
return npmScriptRunner.StdOut.WaitForMatch( await npmScriptRunner.StdOut.WaitForMatch(
new Regex("chunk", RegexOptions.None, RegexMatchTimeout), new Regex("Date", RegexOptions.None, RegexMatchTimeout),
BuildTimeout); BuildTimeout);
} }
catch (EndOfStreamException ex) catch (EndOfStreamException ex)
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
$"The NPM script '{_npmScriptName}' exited without indicating success. " + $"The NPM script '{_npmScriptName}' exited without indicating success.\n" +
$"Output was: {stdOutReader.ReadAsString()}\n" +
$"Error output was: {stdErrReader.ReadAsString()}", ex);
}
catch (OperationCanceledException ex)
{
throw new InvalidOperationException(
$"The NPM script '{_npmScriptName}' timed out without indicating success. " +
$"Output was: {stdOutReader.ReadAsString()}\n" +
$"Error output was: {stdErrReader.ReadAsString()}", ex); $"Error output was: {stdErrReader.ReadAsString()}", ex);
} }
} }