You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Is this something people actually need to catch? If not, consider not making it public.// And if they do need to catch it, is it actually different enough from any existing exception to warrant a new type?publicclassCommandLineConfigurationException:Exception,System.Runtime.Serialization.ISerializable
I am not sure which exception we should use instead:
ValidationException has the right name, but it does not support .NET Standard 2.0 and it might end up creating unnecessary dependency
dictionary throws ArgumentException when a duplicate is being added, but here the exception does not refer to the argument provided to the method, rather to the state of the validate object
I think that we went down this same path before giving up and deciding to use a custom exception type. InvalidOperationException feels a little wrong here because it would imply that the CommandLineConfiguration instance is not in the correct state to be validated.
InvalidOperationException feels a little wrong here because it would imply that the CommandLineConfiguration instance is not in the correct state to be validated.
If the method were instead called RequireValid then InvalidOperationException would feel less wrong.
Another option is to return the error instead of throwing it. Unfortunately ValidationResult is not in .NET Standard 2.0 either.
Is something like public string Validate() used anywhere else? Windows Forms has ErrorProvider with string GetError(Control) but that just retrieves a previously stored error string instead of validating any data during the call.
Activity
adamsitnik commentedon Nov 4, 2022
I am not sure which exception we should use instead:
ArgumentExceptionwhen a duplicate is being added, but here the exception does not refer to the argument provided to the method, rather to the state of the validate objectKalleOlaviNiemitalo commentedon Nov 4, 2022
CommandLineConfigurationException is thrown for two possible errors:
command-line-api/src/System.CommandLine/CommandLineConfiguration.cs
Line 129 in e965ae2
command-line-api/src/System.CommandLine/CommandLineConfiguration.cs
Line 145 in e965ae2
Some candidates from .NET Standard 2.0:
InvalidOperationException seems best.
replace CommandLineConfigurationException with InvalidOperationExcept…
jonsequitur commentedon Nov 4, 2022
I think that we went down this same path before giving up and deciding to use a custom exception type.
InvalidOperationExceptionfeels a little wrong here because it would imply that theCommandLineConfigurationinstance is not in the correct state to be validated.KalleOlaviNiemitalo commentedon Nov 4, 2022
Did Stream.ObjectInvariant() ever throw anything?
KalleOlaviNiemitalo commentedon Nov 5, 2022
If the method were instead called RequireValid then InvalidOperationException would feel less wrong.
Another option is to return the error instead of throwing it. Unfortunately ValidationResult is not in .NET Standard 2.0 either.
Is something like
public string Validate()used anywhere else? Windows Forms has ErrorProvider with string GetError(Control) but that just retrieves a previously stored error string instead of validating any data during the call.