Skip to content

Commit 2b307e0

Browse files
Fix null message regression after quiet logger addition (#44)
The `Microsoft.Build.Utilities.Core` LogError requires a non-null string. In the refactoring, the usages of LogError fell into a new overload of LogError which was passing a null message as the first two arguments of LogError signature were the same. This removes the old logger and adds more protections for this case.
1 parent e7ac499 commit 2b307e0

5 files changed

Lines changed: 10 additions & 87 deletions

File tree

src/Task/AggregateConfig.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ public override bool Execute()
9797
if (!Enum.TryParse(OutputType, true, out FileType outputType) ||
9898
!Enum.IsDefined(typeof(FileType), outputType))
9999
{
100-
logger.LogError("Invalid FileType: {0}. Available options: {1}", OutputType, string.Join(", ", Enum.GetNames(typeof(FileType))));
100+
logger.LogError(message: "Invalid FileType: {0}. Available options: {1}", OutputType, string.Join(", ", Enum.GetNames(typeof(FileType))));
101101
return false;
102102
}
103103

104104
FileType inputType = FileType.Yaml;
105105
if (!string.IsNullOrEmpty(InputType) &&
106106
(!Enum.TryParse(InputType, true, out inputType) || !Enum.IsDefined(typeof(FileType), inputType)))
107107
{
108-
logger.LogError("Invalid FileType: {0}. Available options: {1}", InputType, string.Join(", ", Enum.GetNames(typeof(FileType))));
108+
logger.LogError(message: "Invalid FileType: {0}. Available options: {1}", InputType, string.Join(", ", Enum.GetNames(typeof(FileType))));
109109
return false;
110110
}
111111

@@ -121,7 +121,7 @@ public override bool Execute()
121121

122122
if (finalResult == null)
123123
{
124-
logger.LogError("No input was found! Check the input directory.");
124+
logger.LogError(message: "No input was found! Check the input directory.");
125125
return false;
126126
}
127127

@@ -136,7 +136,7 @@ public override bool Execute()
136136
}
137137
catch (Exception ex)
138138
{
139-
logger.LogError("An unknown exception occurred: {0}", ex.Message);
139+
logger.LogError(message: "An unknown exception occurred: {0}", ex.Message);
140140
logger.LogErrorFromException(ex, true, true, null);
141141
return false;
142142
}

src/Task/Logger/ITaskLogger.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,6 @@ public interface ITaskLogger
1616
/// <param name="messageArgs">Optional arguments for formatting the message.</param>
1717
void LogError(string message = null, params object[] messageArgs);
1818

19-
/// <summary>
20-
/// Logs an error message with additional parameters.
21-
/// </summary>
22-
/// <param name="subcategory">The subcategory of the error.</param>
23-
/// <param name="errorCode">The error code.</param>
24-
/// <param name="helpKeyword">The help keyword associated with the error.</param>
25-
/// <param name="file">The file in which the error occurred.</param>
26-
/// <param name="lineNumber">The line number where the error occurred.</param>
27-
/// <param name="columnNumber">The column number where the error occurred.</param>
28-
/// <param name="endLineNumber">The end line number of the error.</param>
29-
/// <param name="endColumnNumber">The end column number of the error.</param>
30-
/// <param name="message">The error message to log.</param>
31-
/// <param name="messageArgs">Optional arguments for formatting the message.</param>
32-
void LogError(
33-
string subcategory = null,
34-
string errorCode = null,
35-
string helpKeyword = null,
36-
string file = null,
37-
int lineNumber = 0,
38-
int columnNumber = 0,
39-
int endLineNumber = 0,
40-
int endColumnNumber = 0,
41-
string message = null,
42-
params object[] messageArgs);
43-
4419
/// <summary>
4520
/// Logs an error message from an exception.
4621
/// </summary>

src/Task/Logger/QuietTaskLogger.cs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,9 @@ public QuietTaskLogger(TaskLoggingHelper task)
2424
}
2525

2626
/// <inheritdoc />
27-
public void LogError(string message = null, params object[] messageArgs)
27+
public void LogError(string message, params object[] messageArgs)
2828
{
29-
Log.LogError(message, messageArgs);
30-
}
31-
32-
/// <inheritdoc />
33-
public void LogError(
34-
string subcategory = null,
35-
string errorCode = null,
36-
string helpKeyword = null,
37-
string file = null,
38-
int lineNumber = 0,
39-
int columnNumber = 0,
40-
int endLineNumber = 0,
41-
int endColumnNumber = 0,
42-
string message = null,
43-
params object[] messageArgs)
44-
{
45-
Log.LogError(
46-
subcategory,
47-
errorCode,
48-
helpKeyword,
49-
file,
50-
lineNumber,
51-
columnNumber,
52-
endLineNumber,
53-
endColumnNumber,
54-
message,
55-
messageArgs);
29+
Log.LogError(message ?? "Unknown Error", messageArgs);
5630
}
5731

5832
/// <inheritdoc />

src/Task/Logger/TaskLogger.cs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,9 @@ public TaskLogger(TaskLoggingHelper task)
2222
}
2323

2424
/// <inheritdoc />
25-
public void LogError(string message = null, params object[] messageArgs)
25+
public void LogError(string message, params object[] messageArgs)
2626
{
27-
Log.LogError(message, messageArgs);
28-
}
29-
30-
/// <inheritdoc />
31-
public void LogError(
32-
string subcategory = null,
33-
string errorCode = null,
34-
string helpKeyword = null,
35-
string file = null,
36-
int lineNumber = 0,
37-
int columnNumber = 0,
38-
int endLineNumber = 0,
39-
int endColumnNumber = 0,
40-
string message = null,
41-
params object[] messageArgs)
42-
{
43-
Log.LogError(
44-
subcategory,
45-
errorCode,
46-
helpKeyword,
47-
file,
48-
lineNumber,
49-
columnNumber,
50-
endLineNumber,
51-
endColumnNumber,
52-
message,
53-
messageArgs);
27+
Log.LogError(message ?? "Unknown Error", messageArgs);
5428
}
5529

5630
/// <inheritdoc />

src/Task/ObjectManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ await fileGroups.ForEachAsync(Environment.ProcessorCount,
5353
catch (ArgumentException ex)
5454
{
5555
hasError = true;
56-
log.LogError("No reader found for file {0}: {1} Stacktrace: {2}", file, ex.Message, ex.StackTrace);
56+
log.LogError(message: "No reader found for file {0}: {1} Stacktrace: {2}", file, ex.Message, ex.StackTrace);
5757
continue;
5858
}
5959

@@ -65,7 +65,7 @@ await fileGroups.ForEachAsync(Environment.ProcessorCount,
6565
catch (Exception ex)
6666
{
6767
hasError = true;
68-
log.LogError("Could not parse {0}: {1}", file, ex.Message);
68+
log.LogError(message: "Could not parse {0}: {1}", file, ex.Message);
6969
log.LogErrorFromException(ex, true, true, file);
7070
continue;
7171
}

0 commit comments

Comments
 (0)