dotnet / dotnet/command-line-api

ConvertString should return Failure(...) when a string ctor fails instead of propagating the exception.

オープン
#696 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
C#
スター
3.7k
フォーク
428
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

src/System.CommandLine/ArgumentConverter.cs から始め、特に 77–82 行付近の文字列コンストラクターのパスと、61–70 行付近の TypeConverter の例外処理を確認します。両方のパスでコンストラクターの例外をどのように処理しているかを比較します。文字列コンストラクターの失敗が Failure(...) を返し、例外とスタックトレースを伝播させる代わりに、ユーザーフレンドリーなコマンドラインメッセージを表示すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp
領域
cli
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。