Skip to content

Commit

Permalink
Allow BuildEventContext to be null.
Browse files Browse the repository at this point in the history
Fixes #662
  • Loading branch information
KirillOsenkov committed Mar 14, 2023
1 parent 512f695 commit 13a3758
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/StructuredLogger/Construction/MessageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Process(BuildMessageEventArgs args)
}

var buildEventContext = args.BuildEventContext;
if (buildEventContext.TaskId != BuildEventContext.InvalidTaskId)
if (buildEventContext != null && buildEventContext.TaskId != BuildEventContext.InvalidTaskId)
{
if (message.StartsWith(Strings.OutputItemsMessagePrefix, StringComparison.Ordinal))
{
Expand Down Expand Up @@ -94,7 +94,7 @@ public void Process(BuildMessageEventArgs args)
}
}
}
else if (buildEventContext.TargetId != BuildEventContext.InvalidTargetId)
else if (buildEventContext != null && buildEventContext.TargetId != BuildEventContext.InvalidTargetId)
{
if (message.StartsWith(Strings.ItemGroupIncludeMessagePrefix, StringComparison.Ordinal))
{
Expand Down Expand Up @@ -124,7 +124,7 @@ public void Process(BuildMessageEventArgs args)
return;
}
}
else if (buildEventContext.EvaluationId != BuildEventContext.InvalidEvaluationId)
else if (buildEventContext != null && buildEventContext.EvaluationId != BuildEventContext.InvalidEvaluationId)
{
}
else
Expand Down Expand Up @@ -392,7 +392,7 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message)

var buildEventContext = args.BuildEventContext;

if (buildEventContext.TaskId > 0)
if (buildEventContext != null && buildEventContext.TaskId > 0)
{
parent = GetTask(args);
if (parent is Task task)
Expand Down Expand Up @@ -431,7 +431,7 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message)
}
}
}
else if (buildEventContext.TargetId > 0)
else if (buildEventContext != null && buildEventContext.TargetId > 0)
{
parent = GetTarget(args);

Expand All @@ -440,7 +440,7 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message)
lowRelevance = true;
}
}
else if (buildEventContext.ProjectContextId > 0)
else if (buildEventContext != null && buildEventContext.ProjectContextId > 0)
{
var project = construction.GetOrAddProject(buildEventContext.ProjectContextId);
parent = project;
Expand Down Expand Up @@ -470,7 +470,7 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message)
}
}
}
else if (buildEventContext.EvaluationId != -1)
else if (buildEventContext != null && buildEventContext.EvaluationId != -1)
{
parent = construction.EvaluationFolder;

Expand Down Expand Up @@ -533,6 +533,7 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message)
lowRelevance = true;
}
else if (
buildEventContext != null &&
buildEventContext.NodeId == 0 &&
buildEventContext.ProjectContextId == 0 &&
buildEventContext.ProjectInstanceId == 0 &&
Expand All @@ -551,6 +552,7 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message)
return;
}
else if (
buildEventContext != null &&
buildEventContext.NodeId == -2 &&
buildEventContext.ProjectContextId == -2 &&
buildEventContext.ProjectInstanceId == -1)
Expand Down

0 comments on commit 13a3758

Please sign in to comment.