Skip to content

Commit

Permalink
Merge pull request cake-contrib#189 from ap0llo/fix-formatexception-w…
Browse files Browse the repository at this point in the history
…hen-log-message-contains-brackets

Fix FormatException in GitLabCILog when log message contains curly braces
  • Loading branch information
nils-a authored Feb 16, 2024
2 parents 74cee1f + 745189d commit a285922
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Cake.GitLabCI.Module/GitLabCILog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ public void Write(Verbosity verbosity, LogLevel level, string format, params obj
message = $"{level}: {string.Format(format, args)}";
}

// Passing a string to IConsole.WriteLine() / IConsole.WriteErrorLine() will cause that string to be interpreted as format string.
// This will cause an error if the string contains curly braces and WriteLine() will faile with a FormatException.
// To avoid this, pass in the "no-op" format string and pass the text to write to the console as argument that will be formatted into the format string
if (level > LogLevel.Error)
{
_console.WriteLine(message);
_console.WriteLine("{0}", message);
}
else
{
_console.WriteErrorLine(message);
_console.WriteErrorLine("{0}", message);
}
}
}
Expand Down

0 comments on commit a285922

Please sign in to comment.