System.CommandLine.Rendering.AnsiControlCode defines an implicit conversion from String. If the string is null or empty, then the conversion throws ArgumentException. IIRC, implicit conversions should not throw. Perhaps it would be better to make the conversion explicit, or remove it and make src/System.CommandLine.Rendering/Ansi.cs just use the constructor like new($"{Esc}[0m");.
|
public static implicit operator AnsiControlCode(string sequence) |
|
{ |
|
return new AnsiControlCode(sequence); |
|
} |
|
public AnsiControlCode(string escapeSequence) |
|
{ |
|
if (string.IsNullOrWhiteSpace(escapeSequence)) |
|
{ |
|
throw new ArgumentException("Value cannot be null or whitespace.", nameof(escapeSequence)); |
Found while searching for bugs similar to #1797.
System.CommandLine.Rendering.AnsiControlCode defines an implicit conversion from String. If the string is null or empty, then the conversion throws ArgumentException. IIRC, implicit conversions should not throw. Perhaps it would be better to make the conversion explicit, or remove it and make src/System.CommandLine.Rendering/Ansi.cs just use the constructor like
new($"{Esc}[0m");.command-line-api/src/System.CommandLine.Rendering/AnsiControlCode.cs
Lines 54 to 57 in 209b724
command-line-api/src/System.CommandLine.Rendering/AnsiControlCode.cs
Lines 11 to 15 in 209b724
Found while searching for bugs similar to #1797.