Streamlines error message prefixes (#218)

This commit is contained in:
Dor 2019-06-21 11:05:58 -07:00 коммит произвёл GitHub
Родитель b6e351bd3b
Коммит d67bc53bbe
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 41 добавлений и 21 удалений

Просмотреть файл

@ -76,7 +76,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
catch (InvalidUsageException ex)
{
_logger.LogError(ex, "Invalid usage");
_console.Error.WriteLine(ex.Message);
_console.WriteErrorLine(ex.Message);
return false;
}
}

Просмотреть файл

@ -209,6 +209,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
return;
}
// Not using IConsole.WriteErrorLine intentionally, to keep the child's error stream intact
console.Error.WriteLine(args.Data);
buildScriptOutput.AppendLine(args.Data);
};
@ -256,7 +257,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
if (!Directory.Exists(options.SourceDir))
{
logger.LogError("Could not find the source directory {srcDir}", options.SourceDir);
console.Error.WriteLine($"Error: Could not find the source directory '{options.SourceDir}'.");
console.WriteErrorLine($"Could not find the source directory '{options.SourceDir}'.");
return false;
}
@ -264,7 +265,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
if (string.IsNullOrEmpty(options.Language) && !string.IsNullOrEmpty(options.LanguageVersion))
{
logger.LogError("Cannot use lang version without lang name");
console.Error.WriteLine("Cannot use language version without specifying language name also.");
console.WriteErrorLine("Cannot use language version without specifying language name also.");
return false;
}
@ -277,7 +278,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
"Intermediate directory {intermediateDir} cannot be a child of {srcDir}",
options.IntermediateDir,
options.SourceDir);
console.Error.WriteLine(
console.WriteErrorLine(
$"Intermediate directory '{options.IntermediateDir}' cannot be a " +
$"sub-directory of source directory '{options.SourceDir}'.");
return false;

Просмотреть файл

@ -63,14 +63,14 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
if (!Directory.Exists(options.SourceDir))
{
console.Error.WriteLine($"Error: Could not find the source directory '{options.SourceDir}'.");
console.WriteErrorLine($"Could not find the source directory '{options.SourceDir}'.");
return false;
}
// Invalid to specify language version without language name
if (string.IsNullOrEmpty(options.Language) && !string.IsNullOrEmpty(options.LanguageVersion))
{
console.Error.WriteLine("Cannot use language version without specifying language name also.");
console.WriteErrorLine("Cannot use language version without specifying language name also.");
return false;
}

Просмотреть файл

@ -36,7 +36,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
if (!Directory.Exists(LayersDir))
{
logger.LogError("Could not find layers directory {layersDir}", LayersDir);
console.Error.WriteLine($"Error: Could not find layers directory '{LayersDir}'.");
console.WriteErrorLine($"Could not find layers directory '{LayersDir}'.");
result = false;
}
}
@ -47,7 +47,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
if (!File.Exists(PlanPath))
{
logger?.LogError("Could not find build plan file {planPath}", PlanPath);
console.Error.WriteLine($"Error: Could not find build plan file '{PlanPath}'.");
console.WriteErrorLine($"Could not find build plan file '{PlanPath}'.");
result = false;
}
}
@ -58,7 +58,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
if (!Directory.Exists(PlatformDir))
{
logger?.LogError("Could not find platform directory {platformDir}", PlatformDir);
console.Error.WriteLine($"Error: Could not find platform directory '{PlatformDir}'.");
console.WriteErrorLine($"Could not find platform directory '{PlatformDir}'.");
result = false;
}
}

Просмотреть файл

@ -43,7 +43,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
if (!Directory.Exists(options.SourceDir))
{
logger.LogError("Could not find the source directory {srcDir}", options.SourceDir);
console.Error.WriteLine($"Error: Could not find the source directory '{options.SourceDir}'.");
console.WriteErrorLine($"Could not find the source directory '{options.SourceDir}'.");
result = false;
}
@ -53,7 +53,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
if (!File.Exists(PlanPath))
{
logger?.LogError("Could not find build plan file {planPath}", PlanPath);
console.Error.WriteLine($"Error: Could not find build plan file '{PlanPath}'.");
console.WriteErrorLine($"Could not find build plan file '{PlanPath}'.");
result = false;
}
}
@ -64,7 +64,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
if (!Directory.Exists(PlatformDir))
{
logger?.LogError("Could not find platform directory {platformDir}", PlatformDir);
console.Error.WriteLine($"Error: Could not find platform directory '{PlatformDir}'.");
console.WriteErrorLine($"Could not find platform directory '{PlatformDir}'.");
result = false;
}
}

Просмотреть файл

@ -49,18 +49,17 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
}
catch (InvalidUsageException e)
{
console.Error.WriteLine(e.Message);
console.WriteErrorLine(e.Message);
return ProcessConstants.ExitFailure;
}
catch (Exception exc)
{
_serviceProvider?.GetRequiredService<ILogger<CommandBase>>()?.LogError(exc, "Exception caught");
console.Error.WriteLine(Constants.GenericErrorMessage);
console.WriteErrorLine(Constants.GenericErrorMessage);
if (ShowStackTrace)
{
console.Error.WriteLine("Exception.ToString():");
console.Error.WriteLine(exc.ToString());
console.WriteErrorLine(exc.ToString());
}
return ProcessConstants.ExitFailure;

Просмотреть файл

@ -48,7 +48,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
var script = scriptGenerator.GenerateBashScript(Platform, options);
if (string.IsNullOrEmpty(script))
{
console.Error.WriteLine("Error: Couldn't generate startup script.");
console.WriteErrorLine("Couldn't generate startup script.");
return ProcessConstants.ExitFailure;
}
@ -61,7 +61,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
{
if (!Directory.Exists(InstallationPrefix))
{
console.Error.WriteLine($"Error: Could not find the installation prefix directory '{InstallationPrefix}'.");
console.WriteErrorLine($"Could not find the installation prefix directory '{InstallationPrefix}'.");
return false;
}

Просмотреть файл

@ -48,7 +48,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
{
if (string.IsNullOrWhiteSpace(PlatformName))
{
console.Error.WriteLine("Platform name is required.");
console.WriteErrorLine("Platform name is required.");
return ProcessConstants.ExitFailure;
}
@ -67,7 +67,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
var script = runScriptGenerator.GenerateBashScript(PlatformName, options);
if (string.IsNullOrEmpty(script))
{
console.Error.WriteLine("Error: Couldn't generate startup script.");
console.WriteErrorLine("Couldn't generate startup script.");
return ProcessConstants.ExitFailure;
}
@ -91,7 +91,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
{
if (!Directory.Exists(AppDir))
{
console.Error.WriteLine($"Error: Could not find the directory '{AppDir}'.");
console.WriteErrorLine($"Could not find the directory '{AppDir}'.");
return false;
}

Просмотреть файл

@ -0,0 +1,20 @@
// --------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// --------------------------------------------------------------------------------------------
using McMaster.Extensions.CommandLineUtils;
namespace Microsoft.Oryx.BuildScriptGeneratorCli
{
internal static class IConsoleExtensions
{
public static void WriteErrorLine(this IConsole console, string message)
{
if (!string.IsNullOrWhiteSpace(message))
{
console.Error.WriteLine("Error: " + message);
}
}
}
}