Skip to content

Commit

Permalink
Merge pull request #3142 from norpache/better-error-msg-for-circular-ref
Browse files Browse the repository at this point in the history
GH-1616: Better error message for interdependent tasks
  • Loading branch information
augustoproiete committed Oct 14, 2021
2 parents 87bb27b + 291ddc2 commit 61a7dfb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Cake.Core.Tests/Unit/Graph/CakeGraphTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Linq;
using Cake.Core.Graph;
using Xunit;
Expand Down Expand Up @@ -152,7 +153,7 @@ public void Should_Throw_If_Edge_Is_Unidirectional()

// Then
Assert.IsType<CakeException>(result);
Assert.Equal("Unidirectional edges in graph are not allowed.", result?.Message);
Assert.Equal($"Unidirectional edges in graph are not allowed.{Environment.NewLine}\"start\" and \"end\" cannot depend on each other.", result?.Message);
}

[Fact]
Expand All @@ -167,7 +168,7 @@ public void Should_Throw_If_Edge_Is_Unidirectional_Regardless_Of_Casing()

// Then
Assert.IsType<CakeException>(result);
Assert.Equal("Unidirectional edges in graph are not allowed.", result?.Message);
Assert.Equal($"Unidirectional edges in graph are not allowed.{Environment.NewLine}\"start\" and \"end\" cannot depend on each other.", result?.Message);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Cake.Core/Graph/CakeGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public void Connect(string start, string end)
if (_edges.Any(x => x.Start.Equals(end, StringComparison.OrdinalIgnoreCase)
&& x.End.Equals(start, StringComparison.OrdinalIgnoreCase)))
{
throw new CakeException("Unidirectional edges in graph are not allowed.");
var firstBadEdge = _edges.First(x => x.Start.Equals(end, StringComparison.OrdinalIgnoreCase) && x.End.Equals(start, StringComparison.OrdinalIgnoreCase));
throw new CakeException($"Unidirectional edges in graph are not allowed.{Environment.NewLine}\"{firstBadEdge.Start}\" and \"{firstBadEdge.End}\" cannot depend on each other.");
}
if (_edges.Any(x => x.Start.Equals(start, StringComparison.OrdinalIgnoreCase)
&& x.End.Equals(end, StringComparison.OrdinalIgnoreCase)))
Expand Down

0 comments on commit 61a7dfb

Please sign in to comment.