dotnet / dotnet/command-line-api
ConvertString should return Failure(...) when a string ctor fails instead of propagating the exception.
- Lenguaje dominante
- C#
- Estrellas
- 3.7k
- Forks
- 428
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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.
Guía de contribución
Línea de trabajo
Empieza en src/System.CommandLine/ArgumentConverter.cs, especialmente en la ruta del constructor de strings alrededor de las líneas 77–82 y en el manejo de excepciones de TypeConverter alrededor de las líneas 61–70. Compara cómo ambas rutas manejan las excepciones de los constructores. La tarea estará terminada cuando los fallos del constructor de strings devuelvan Failure(...) y muestren un mensaje de línea de comandos comprensible para el usuario en lugar de propagar una excepción y un stack trace.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- csharp
- Área
- cli
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 48/100