Log template errors as debug messages under feature flag

This commit is contained in:
JoannaaKL
2023-06-01 14:13:06 +00:00
committed by GitHub
parent 7c1ea89b87
commit d056e8fa08
3 changed files with 12 additions and 7 deletions

View File

@@ -155,6 +155,7 @@ namespace GitHub.Runner.Common
{
public static readonly string DiskSpaceWarning = "runner.diskspace.warning";
public static readonly string Node12Warning = "DistributedTask.AddWarningToNode12Action";
public static readonly string LogTemplateErrorsAsDebugMessage = "DistributedTask.LogTemplateErrorsAsDebugMessage";
public static readonly string UseContainerPathForTemplate = "DistributedTask.UseContainerPathForTemplate";
public static readonly string AllowRunnerContainerHooks = "DistributedTask.AllowRunnerContainerHooks";
}

View File

@@ -21,6 +21,7 @@ using Newtonsoft.Json;
using Sdk.RSWebApi.Contracts;
using ObjectTemplating = GitHub.DistributedTask.ObjectTemplating;
using Pipelines = GitHub.DistributedTask.Pipelines;
using constants = GitHub.Runner.Common.Constants;
namespace GitHub.Runner.Worker
{
@@ -1401,8 +1402,14 @@ namespace GitHub.Runner.Worker
public void Error(string format, params Object[] args)
{
_executionContext.Error(string.Format(CultureInfo.CurrentCulture, format, args));
_executionContext.Global.EnvironmentVariables.TryGetValue(Constants.Runner.Features.LogTemplateErrorsAsDebugMessage, out var logErrorsAsDebug);
if (StringUtil.ConvertToBoolean(logErrorsAsDebug, defaultValue: false))
{
_executionContext.Debug(string.Format(CultureInfo.CurrentCulture, format, args));
}
else _executionContext.Error(string.Format(CultureInfo.CurrentCulture, format, args));
}
public void Info(string format, params Object[] args)
{

View File

@@ -152,13 +152,10 @@ namespace GitHub.DistributedTask.ObjectTemplating
String message)
{
var prefix = GetErrorPrefix(fileId, line, column);
if (!String.IsNullOrEmpty(prefix))
{
message = $"{prefix} {message}";
}
var fullMessage = !String.IsNullOrEmpty(prefix) ? $"{prefix} {message}" : message;
Errors.Add(message);
TraceWriter.Error(message);
Errors.Add(fullMessage);
TraceWriter.Error(fullMessage);
}
internal INamedValueInfo[] GetExpressionNamedValues()