dotnet / dotnet/command-line-api
ConvertString should return Failure(...) when a string ctor fails instead of propagating the exception.
- Vorherrschende Sprache
- C#
- Sterne
- 3.7k
- Forks
- 428
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Currently, when an argument is bound to a type with a constructor that accepts a string, if that constructor throws an exception (for example, if validation fails), the exception is propagated and a stack trace is displayed on the command line.
Compare this to when conversion fails using the same constructor, but from within a custom `TypeConverter`. Instead of propagating the exception, the `ConvertString` method returns `Failure(...)` and a much more user-friendly message is displayed on the command line.
This section has no exception handling:
https://github.com/dotnet/command-line-api/blob/d9fea6f36bf23fa174656bb5e8299c03c07b5494/src/System.CommandLine/ArgumentConverter.cs#L77-L82
vs. this, in the same method, which handles exceptions thrown during type conversion:
https://github.com/dotnet/command-line-api/blob/d9fea6f36bf23fa174656bb5e8299c03c07b5494/src/System.CommandLine/ArgumentConverter.cs#L61-L70
It would be preferable if both scenarios handled exceptions and generated more user-friendly responses.
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.