Skip to content

Commit 8cd7268

Browse files
committed
replace CommandLineConfigurationException with InvalidOperationException, fixes dotnet#1909
1 parent 6cd2235 commit 8cd7268

File tree

4 files changed

+12
-49
lines changed

4 files changed

+12
-49
lines changed

src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt

-4
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ System.CommandLine
103103
public System.Boolean EnableTokenReplacement { get; }
104104
public LocalizationResources LocalizationResources { get; }
105105
public Command RootCommand { get; }
106-
public class CommandLineConfigurationException : System.Exception, System.Runtime.Serialization.ISerializable
107-
.ctor(System.String message)
108-
.ctor()
109-
.ctor(System.String message, System.Exception innerException)
110106
public System.Void Validate()
111107
public static class CompletionSourceExtensions
112108
public static System.Void Add(this CompletionSourceList completionSources, System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.String>> complete)

src/System.CommandLine.Tests/CommandLineConfigurationTests.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void ThrowIfInvalid_throws_if_there_are_duplicate_sibling_option_aliases_
2626
var validate = () => config.Validate();
2727

2828
validate.Should()
29-
.Throw<CommandLineConfigurationException>()
29+
.Throw<InvalidOperationException>()
3030
.Which
3131
.Message
3232
.Should()
@@ -54,7 +54,7 @@ public void ThrowIfInvalid_throws_if_there_are_duplicate_sibling_option_aliases_
5454
var validate = () => config.Validate();
5555

5656
validate.Should()
57-
.Throw<CommandLineConfigurationException>()
57+
.Throw<InvalidOperationException >()
5858
.Which
5959
.Message
6060
.Should()
@@ -79,7 +79,7 @@ public void ThrowIfInvalid_throws_if_there_are_duplicate_sibling_subcommand_alia
7979
var validate = () => config.Validate();
8080

8181
validate.Should()
82-
.Throw<CommandLineConfigurationException>()
82+
.Throw<InvalidOperationException >()
8383
.Which
8484
.Message
8585
.Should()
@@ -107,7 +107,7 @@ public void ThrowIfInvalid_throws_if_there_are_duplicate_sibling_subcommand_alia
107107
var validate = () => config.Validate();
108108

109109
validate.Should()
110-
.Throw<CommandLineConfigurationException>()
110+
.Throw<InvalidOperationException >()
111111
.Which
112112
.Message
113113
.Should()
@@ -132,7 +132,7 @@ public void ThrowIfInvalid_throws_if_sibling_command_and_option_aliases_collide_
132132
var validate = () => config.Validate();
133133

134134
validate.Should()
135-
.Throw<CommandLineConfigurationException>()
135+
.Throw<InvalidOperationException >()
136136
.Which
137137
.Message
138138
.Should()
@@ -160,7 +160,7 @@ public void ThrowIfInvalid_throws_if_sibling_command_and_option_aliases_collide_
160160
var validate = () => config.Validate();
161161

162162
validate.Should()
163-
.Throw<CommandLineConfigurationException>()
163+
.Throw<InvalidOperationException >()
164164
.Which
165165
.Message
166166
.Should()
@@ -183,7 +183,7 @@ public void ThrowIfInvalid_throws_if_there_are_duplicate_sibling_global_option_a
183183
var validate = () => config.Validate();
184184

185185
validate.Should()
186-
.Throw<CommandLineConfigurationException>()
186+
.Throw<InvalidOperationException >()
187187
.Which
188188
.Message
189189
.Should()
@@ -239,7 +239,7 @@ public void ThrowIfInvalid_throws_if_a_command_is_its_own_parent()
239239
var validate = () => config.Validate();
240240

241241
validate.Should()
242-
.Throw<CommandLineConfigurationException>()
242+
.Throw<InvalidOperationException >()
243243
.Which
244244
.Message
245245
.Should()
@@ -258,7 +258,7 @@ public void ThrowIfInvalid_throws_if_a_parentage_cycle_is_detected()
258258
var validate = () => config.Validate();
259259

260260
validate.Should()
261-
.Throw<CommandLineConfigurationException>()
261+
.Throw<InvalidOperationException >()
262262
.Which
263263
.Message
264264
.Should()

src/System.CommandLine/CommandLineConfiguration.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private bool DefaultTokenReplacer(
117117
/// Throws an exception if the parser configuration is ambiguous or otherwise not valid.
118118
/// </summary>
119119
/// <remarks>Due to the performance cost of this method, it is recommended to be used in unit testing or in scenarios where the parser is configured dynamically at runtime.</remarks>
120-
/// <exception cref="CommandLineConfigurationException">Thrown if the configuration is found to be invalid.</exception>
120+
/// <exception cref="InvalidOperationException ">Thrown if the configuration is found to be invalid.</exception>
121121
public void Validate()
122122
{
123123
ThrowIfInvalid(RootCommand);
@@ -126,7 +126,7 @@ static void ThrowIfInvalid(Command command)
126126
{
127127
if (command.Parents.FlattenBreadthFirst(c => c.Parents).Any(ancestor => ancestor == command))
128128
{
129-
throw new CommandLineConfigurationException($"Cycle detected in command tree. Command '{command.Name}' is its own ancestor.");
129+
throw new InvalidOperationException($"Cycle detected in command tree. Command '{command.Name}' is its own ancestor.");
130130
}
131131

132132
int count = command.Subcommands.Count + command.Options.Count;
@@ -142,7 +142,7 @@ static void ThrowIfInvalid(Command command)
142142
if (symbol1AsIdentifier.Name.Equals(symbol2Alias, StringComparison.Ordinal) ||
143143
symbol1AsIdentifier.Aliases.Contains(symbol2Alias))
144144
{
145-
throw new CommandLineConfigurationException($"Duplicate alias '{symbol2Alias}' found on command '{command.Name}'.");
145+
throw new InvalidOperationException($"Duplicate alias '{symbol2Alias}' found on command '{command.Name}'.");
146146
}
147147
}
148148
}

src/System.CommandLine/CommandLineConfigurationException.cs

-33
This file was deleted.

0 commit comments

Comments
 (0)