Skip to content

Commit

Permalink
Fixed issues relating to receiving an MSBuild warning/error that did …
Browse files Browse the repository at this point in the history
…not refer to any file
  • Loading branch information
RedOrbweaver authored and RedOrbweaver committed Aug 29, 2024
1 parent 01c78d8 commit 5f66671
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void eventSource_ErrorRaised(object sender, BuildErrorEventArgs e)

WriteLine(line);

string errorLine = $@"error,{e.File.CsvEscape()},{e.LineNumber},{e.ColumnNumber}," +
string errorLine = $@"error,{e.File?.CsvEscape() ?? string.Empty},{e.LineNumber},{e.ColumnNumber}," +
$"{e.Code?.CsvEscape() ?? string.Empty},{e.Message.CsvEscape()}," +
$"{e.ProjectFile?.CsvEscape() ?? string.Empty}";
_issuesStreamWriter.WriteLine(errorLine);
Expand All @@ -103,9 +103,9 @@ private void eventSource_WarningRaised(object sender, BuildWarningEventArgs e)

WriteLine(line);

string warningLine = $@"warning,{e.File.CsvEscape()},{e.LineNumber},{e.ColumnNumber}," +
$"{e.Code?.CsvEscape() ?? string.Empty},{e.Message.CsvEscape()}," +
$"{e.ProjectFile?.CsvEscape() ?? string.Empty}";
string warningLine = $@"warning,{e.File?.CsvEscape() ?? string.Empty},{e.LineNumber},{e.ColumnNumber}," +
$"{e.Code?.CsvEscape() ?? string.Empty},{e.Message.CsvEscape()}," +
$"{e.ProjectFile?.CsvEscape() ?? string.Empty}";
_issuesStreamWriter.WriteLine(warningLine);
}

Expand Down Expand Up @@ -164,6 +164,11 @@ internal static class StringExtensions
{
public static string CsvEscape(this string value, char delimiter = ',')
{
if (value == null)
{
Console.WriteLine("Warning: Empty string passed to CsvEscape inside the build logger.");
return "";
}
bool hasSpecialChar = value.IndexOfAny(new[] { '\"', '\n', '\r', delimiter }) != -1;

if (hasSpecialChar)
Expand Down
40 changes: 20 additions & 20 deletions modules/mono/editor/GodotTools/GodotTools/Build/BuildOutputView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ private void LoadIssuesFromFile(string csvFile)
var issue = new BuildIssue
{
Warning = csvColumns[0] == "warning",
File = csvColumns[1],
Line = int.Parse(csvColumns[2]),
Column = int.Parse(csvColumns[3]),
Code = csvColumns[4],
Message = csvColumns[5],
ProjectFile = csvColumns[6]
File = csvColumns[1] ?? "",
Line = int.Parse(csvColumns[2] ?? ""),
Column = int.Parse(csvColumns[3] ?? ""),
Code = csvColumns[4] ?? "",
Message = csvColumns[5] ?? "",
ProjectFile = csvColumns[6] ?? ""
};

if (issue.Warning)
Expand Down Expand Up @@ -131,7 +131,7 @@ private void IssueActivated(int idx)

BuildIssue issue = _issues[issueIndex];

if (string.IsNullOrEmpty(issue.ProjectFile) && string.IsNullOrEmpty(issue.File))
if (string.IsNullOrEmpty(issue.ProjectFile) || string.IsNullOrEmpty(issue.File))
return;

string projectDir = issue.ProjectFile.Length > 0 ? issue.ProjectFile.GetBaseDir() : _buildInfo.Solution.GetBaseDir();
Expand Down Expand Up @@ -208,7 +208,7 @@ private void BuildLaunchFailed(BuildInfo buildInfo, string cause)

_issuesList.Clear();

var issue = new BuildIssue {Message = cause, Warning = false};
var issue = new BuildIssue { Message = cause, Warning = false };

ErrorCount += 1;
_issues.Add(issue);
Expand Down Expand Up @@ -315,21 +315,21 @@ private void IssuesListContextOptionPressed(IssuesContextMenuOption id)
switch (id)
{
case IssuesContextMenuOption.Copy:
{
// We don't allow multi-selection but just in case that changes later...
string text = null;

foreach (int issueIndex in _issuesList.GetSelectedItems())
{
// We don't allow multi-selection but just in case that changes later...
string text = null;

foreach (int issueIndex in _issuesList.GetSelectedItems())
{
if (text != null)
text += "\n";
text += _issuesList.GetItemText(issueIndex);
}

if (text != null)
text += "\n";
text += _issuesList.GetItemText(issueIndex);
OS.Clipboard = text;
break;
}

if (text != null)
OS.Clipboard = text;
break;
}
default:
throw new ArgumentOutOfRangeException(nameof(id), id, "Invalid issue context menu option");
}
Expand Down

0 comments on commit 5f66671

Please sign in to comment.