Skip to content

Commit

Permalink
Fix null reference exception where there are no deserialized messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikgolda committed Jun 5, 2019
1 parent 27e2366 commit 3b648e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/Soloplan.WhatsON.CruiseControl/CruiseControlProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ protected override async Task ExecuteQuery(CancellationToken cancellationToken,
/// <returns>Appropriate <see cref="ObservationState"/>.</returns>
private static ObservationState CcStatusToObservationStatus(CruiseControlJob projectData)
{
if (projectData.LastBuildStatus == CcBuildStatus.Success && projectData.MessageList.Messages.All(msg => msg.Kind != MessageKind.FailingTasks && msg.Kind != MessageKind.Breakers && msg.Kind != MessageKind.BuildAbortedBy))
if (projectData.LastBuildStatus == CcBuildStatus.Success && projectData.MessageList.MessagesSafe.All(msg => msg.Kind != MessageKind.FailingTasks && msg.Kind != MessageKind.Breakers && msg.Kind != MessageKind.BuildAbortedBy))
{
return ObservationState.Success;
}

if (projectData.LastBuildStatus == CcBuildStatus.Failure || projectData.LastBuildStatus == CcBuildStatus.Exception || projectData.MessageList.Messages.Any(msg => msg.Kind != MessageKind.FailingTasks && msg.Kind != MessageKind.Breakers))
if (projectData.LastBuildStatus == CcBuildStatus.Failure || projectData.LastBuildStatus == CcBuildStatus.Exception || projectData.MessageList.MessagesSafe.Any(msg => msg.Kind != MessageKind.FailingTasks && msg.Kind != MessageKind.Breakers))
{
return ObservationState.Failure;
}
Expand Down Expand Up @@ -194,21 +194,18 @@ private CruiseControlStatus CreateStatus(CruiseControlJob job)

private static void SetCulprits(CruiseControlJob job, CruiseControlStatus result)
{
if (job.MessageList?.Messages != null)
var breakers = job.MessageList.MessagesSafe.Where(msg => msg.Kind == MessageKind.Breakers);
foreach (var breakersLine in breakers)
{
var breakers = job.MessageList.Messages.Where(msg => msg.Kind == MessageKind.Breakers);
foreach (var breakersLine in breakers)
foreach (var breaker in breakersLine.Text.Split(',').Select(brk => brk.Trim()).Where(brk => !string.IsNullOrEmpty(brk)))
{
foreach (var breaker in breakersLine.Text.Split(',').Select(brk => brk.Trim()).Where(brk => !string.IsNullOrEmpty(brk)))
if (result.Culprits.Any(brk => brk.Name == breaker))
{
if (result.Culprits.Any(brk => brk.Name == breaker))
{
continue;
}

var culprit = new Culprit { Name = breaker };
result.Culprits.Add(culprit);
continue;
}

var culprit = new Culprit { Name = breaker };
result.Culprits.Add(culprit);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Soloplan.WhatsON.CruiseControl/Model/MessageList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ public class MessageList
{
[XmlElement("message")]
public Message[] Messages { get; set; }

[XmlIgnore]
public Message[] MessagesSafe => this.Messages ?? new Message[0];
}
}

0 comments on commit 3b648e0

Please sign in to comment.