Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flip meaning of AllowFailureWithoutError Fixes #5701 #5743

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Build.UnitTests/BackEnd/FailingTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ public class FailingTask : Task
{
public override bool Execute()
{
BuildEngine.GetType().GetProperty("AllowFailureWithoutError").SetValue(BuildEngine, EnableDefaultFailure);
if (!AllowFailureWithoutError.Equals("Default"))
{
BuildEngine.GetType().GetProperty("AllowFailureWithoutError").SetValue(BuildEngine, AllowFailureWithoutError.Equals("True"));
}
return false;
}

[Required]
public bool EnableDefaultFailure { get; set; }
public string AllowFailureWithoutError { get; set; }
}
}
11 changes: 6 additions & 5 deletions src/Build.UnitTests/BackEnd/OnError_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,18 +563,19 @@ public void OutOfOrderOnError()
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public void ErrorWhenTaskFailsWithoutLoggingErrorEscapeHatch(bool emitError)
[InlineData("True")]
[InlineData("False")]
[InlineData("Default")]
public void ErrorWhenTaskFailsWithoutLoggingErrorEscapeHatch(string failureResponse)
{
MockLogger logger = ObjectModelHelpers.BuildProjectExpectFailure($@"
<Project>
<UsingTask TaskName=""FailingTask"" AssemblyFile=""{Assembly.GetExecutingAssembly().Location}"" />
<Target Name=""MyTarget"">
<FailingTask EnableDefaultFailure=""{emitError}"" />
<FailingTask AllowFailureWithoutError=""{failureResponse}"" />
</Target>
</Project>");
if (emitError)
if (!string.Equals(failureResponse, "True"))
{
logger.ErrorCount.ShouldBe(1);
logger.Errors.First().Code.ShouldBe("MSB4181");
Expand Down
2 changes: 1 addition & 1 deletion src/Build/BackEnd/BuildManager/BuildParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public bool UseSynchronousLogging
/// <summary>
/// Indicates whether to emit a default error if a task returns false without logging an error.
/// </summary>
public bool AllowFailureWithoutError { get; set; } = true;
public bool AllowFailureWithoutError { get; set; } = false;

/// <summary>
/// Gets the environment variables which were set when this build was created.
Expand Down
2 changes: 1 addition & 1 deletion src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ private async Task<WorkUnitResult> ExecuteInstantiatedTask(ITaskExecutionHost ta
// that is logged as an error. MSBuild tasks are an exception because
// errors are not logged directly from them, but the tasks spawned by them.
IBuildEngine be = host.TaskInstance.BuildEngine;
if (taskReturned && !taskResult && !taskLoggingContext.HasLoggedErrors && (be is TaskHost th ? th.BuildRequestsSucceeded : false) && (be is IBuildEngine7 be7 ? be7.AllowFailureWithoutError : true))
if (taskReturned && !taskResult && !taskLoggingContext.HasLoggedErrors && (be is TaskHost th ? th.BuildRequestsSucceeded : false) && (be is IBuildEngine7 be7 ? !be7.AllowFailureWithoutError : true))
{
if (_continueOnError == ContinueOnError.WarnAndContinue)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Build/BackEnd/Components/RequestBuilder/TaskHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ public IReadOnlyDictionary<string, string> GetGlobalProperties()
/// <summary>
/// Enables or disables emitting a default error when a task fails without logging errors
/// </summary>
public bool AllowFailureWithoutError { get; set; } = true;
public bool AllowFailureWithoutError { get; set; } = false;
#endregion

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/MSBuild/OutOfProcTaskHostNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public bool IsRunningMultipleNodes
/// <summary>
/// Enables or disables emitting a default error when a task fails without logging errors
/// </summary>
public bool AllowFailureWithoutError { get; set; } = true;
public bool AllowFailureWithoutError { get; set; } = false;
#endregion

#region IBuildEngine Implementation (Methods)
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/UnitTests/MockEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal MockEngine() : this(false)

internal int Errors { get; set; }

public bool AllowFailureWithoutError { get; set; } = true;
public bool AllowFailureWithoutError { get; set; } = false;

public BuildErrorEventArgs[] ErrorEvents => _errorEvents.ToArray();

Expand Down