Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Parsing gives incorrect/unexpected/inconsistent error results

Đang mở
#2,664 8 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
cli

Hướng nghiên cứu

Tái hiện hành vi trong RawApi_Version_Error_tests và RawApi_Help_Error_tests bằng lệnh và các đối số được hiển thị trong issue. So sánh số lượng và thông báo lỗi được báo cáo với hành vi parsing và validation dự kiến. Việc hoàn thành cần thiết lập sự tách biệt rõ ràng, có thể kiểm soát giữa lỗi parsing và validation phụ thuộc vào ứng dụng, bao gồm cả việc xử lý --help và --version.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Area-Parser and Binder

Version: 2.0.0-beta7.25380.108 (Latest NuGet as of this writing)

[TestMethod]
public void RawApi_Version_Error_tests( )
{
    var rootCommand = new RootCommand("Test Root")
    {
        new Option<string>("--option1")
        {
            Description = "Test option `",
            Required = true,
        },
    };

    var result = rootCommand.Parse(["--FooBar", "--version"]);
    Assert.HasCount( 3, result.Errors, "Errors should account for, bogus arg (`--FooBar`), missing required arg (`--option1`), AND that `--version` should be solo" );
}

This test won't pass, the error count is only 2, the error regarding the --version is completely missing.
Errors are:
[0] = "Unrecognized command or argument '--FooBar'."
[1] = "Option '--option1' is required."

For help it's even worse...

[TestMethod]
public void RawApi_Help_Error_tests( )
{
    var rootCommand = new RootCommand("Test Root")
    {
        new Option<string>("--option1")
        {
            Description = "Test option `",
            Required = true,
        },
    };

    var result = rootCommand.Parse(["--FooBar", "--help"]);
    Assert.HasCount( 3, result.Errors, "Errors should account for, bogus arg (`--FooBar`), missing required arg (`--option1`), AND that `--version` should be solo" );
}

This results in NO errors. But the expectation is that an error for the bogus param AND the missing required argument is present. Basically, the problem is one of co-mingling parsing (which is really lex+parse) with validation which is semantic analysis and is VERY application dependent. Ideally, there is a way to disable all validations and move that to a distinct operation the application is in control of.

Ngôn ngữ chính
C#
Star
3.7k
Fork
434
Merge trung bình
4 giờ 46 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dotnet/command-line-api

Tất cả issue của dotnet/command-line-api

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.