Don't fail the build when ExtensionDependencyChecker fails

This commit is contained in:
Ajay Bhargav Baaskaran 2018-04-13 14:12:33 -07:00
parent 8d1de6ec80
commit 60b6ec047d
4 changed files with 28 additions and 16 deletions

View File

@ -161,11 +161,13 @@ namespace Microsoft.AspNetCore.Razor.Tasks
if (result == 0) if (result == 0)
{ {
// Server execution succeeded.
Log.LogMessage(StandardOutputLoggingImportance, $"Server execution completed with return code {result}."); Log.LogMessage(StandardOutputLoggingImportance, $"Server execution completed with return code {result}.");
return true; return true;
} }
else else if (result == 2)
{ {
// Server execution completed with a legit error. No need to fallback to cli execution.
Log.LogMessage(StandardOutputLoggingImportance, $"Server execution completed with return code {result}. For more info, check the server log file in the location specified by the RAZORBUILDSERVER_LOG environment variable."); Log.LogMessage(StandardOutputLoggingImportance, $"Server execution completed with return code {result}. For more info, check the server log file in the location specified by the RAZORBUILDSERVER_LOG environment variable.");
if (LogStandardErrorAsError) if (LogStandardErrorAsError)
@ -179,9 +181,15 @@ namespace Microsoft.AspNetCore.Razor.Tasks
return true; return true;
} }
else
{
// Server execution completed with an error but we still want to fallback to cli execution.
Log.LogMessage(StandardOutputLoggingImportance, $"Server execution completed with return code {result}. For more info, check the server log file in the location specified by the RAZORBUILDSERVER_LOG environment variable.");
}
} }
else else
{ {
// Server execution failed. Fallback to cli execution.
Log.LogMessage( Log.LogMessage(
StandardOutputLoggingImportance, StandardOutputLoggingImportance,
$"Server execution failed with response {response.Type}. For more info, check the server log file in the location specified by the RAZORBUILDSERVER_LOG environment variable."); $"Server execution failed with response {response.Type}. For more info, check the server log file in the location specified by the RAZORBUILDSERVER_LOG environment variable.");

View File

@ -11,6 +11,10 @@ namespace Microsoft.AspNetCore.Razor.Tools
{ {
internal abstract class CommandBase : CommandLineApplication internal abstract class CommandBase : CommandLineApplication
{ {
public const int ExitCodeSuccess = 0;
public const int ExitCodeFailure = 1;
public const int ExitCodeFailureRazorError = 2;
protected CommandBase(Application parent, string name) protected CommandBase(Application parent, string name)
: base(throwOnUnexpectedArg: true) : base(throwOnUnexpectedArg: true)
{ {
@ -46,7 +50,7 @@ namespace Microsoft.AspNetCore.Razor.Tools
if (!ValidateArguments()) if (!ValidateArguments())
{ {
ShowHelp(); ShowHelp();
return 1; return ExitCodeFailureRazorError;
} }
return await ExecuteCoreAsync(); return await ExecuteCoreAsync();

View File

@ -95,17 +95,17 @@ namespace Microsoft.AspNetCore.Razor.Tools
} }
} }
if (!Parent.Checker.Check(ExtensionFilePaths.Values))
{
Error.WriteLine($"Extenions could not be loaded. See output for details.");
return false;
}
return true; return true;
} }
protected override Task<int> ExecuteCoreAsync() protected override Task<int> ExecuteCoreAsync()
{ {
if (!Parent.Checker.Check(ExtensionFilePaths.Values))
{
Error.WriteLine($"Extenions could not be loaded. See output for details.");
return Task.FromResult(ExitCodeFailure);
}
// Loading all of the extensions should succeed as the dependency checker will have already // Loading all of the extensions should succeed as the dependency checker will have already
// loaded them. // loaded them.
var extensions = new RazorExtension[ExtensionNames.Values.Count]; var extensions = new RazorExtension[ExtensionNames.Values.Count];
@ -165,7 +165,7 @@ namespace Microsoft.AspNetCore.Razor.Tools
} }
} }
return 0; return ExitCodeSuccess;
} }
private static byte[] Hash(string path) private static byte[] Hash(string path)

View File

@ -49,6 +49,12 @@ namespace Microsoft.AspNetCore.Razor.Tools
protected override Task<int> ExecuteCoreAsync() protected override Task<int> ExecuteCoreAsync()
{ {
if (!Parent.Checker.Check(ExtensionFilePaths.Values))
{
Error.WriteLine($"Extensions could not be loaded. See output for details.");
return Task.FromResult(ExitCodeFailure);
}
// Loading all of the extensions should succeed as the dependency checker will have already // Loading all of the extensions should succeed as the dependency checker will have already
// loaded them. // loaded them.
var extensions = new RazorExtension[ExtensionNames.Values.Count]; var extensions = new RazorExtension[ExtensionNames.Values.Count];
@ -125,12 +131,6 @@ namespace Microsoft.AspNetCore.Razor.Tools
} }
} }
if (!Parent.Checker.Check(ExtensionFilePaths.Values))
{
Error.WriteLine($"Extensions could not be loaded. See output for details.");
return false;
}
return true; return true;
} }
@ -189,7 +189,7 @@ namespace Microsoft.AspNetCore.Razor.Tools
} }
} }
return success ? 0 : -1; return success ? ExitCodeSuccess : ExitCodeFailureRazorError;
} }
private VirtualRazorProjectFileSystem GetVirtualRazorProjectSystem(SourceItem[] inputItems) private VirtualRazorProjectFileSystem GetVirtualRazorProjectSystem(SourceItem[] inputItems)