dotnet / dotnet/command-line-api
ConvertString should return Failure(...) when a string ctor fails instead of propagating the exception.
- Lingua principale
- C#
- Stelle
- 3.7k
- Fork
- 428
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.