Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullpointer using ValidationFailure without PropertyName using ProblemDetails #618

Closed
Maskoe opened this issue Feb 25, 2024 · 1 comment
Closed
Labels
bug Something isn't working fixed the bug has been squashed

Comments

@Maskoe
Copy link
Contributor

Maskoe commented Feb 25, 2024

Sample

using FastEndpoints;
using FluentValidation.Results;

var bld = WebApplication.CreateBuilder();
bld.Services.AddFastEndpoints();

var app = bld.Build();
app.UseFastEndpoints(x => { x.Errors.UseProblemDetails(); });
app.Run();

public class MyEndpoint : EndpointWithoutRequest
{
    public override void Configure()
    {
        Get("/api/vali");
        AllowAnonymous();
    }

    public override async Task HandleAsync(CancellationToken ct)
    {
        ThrowError(new ValidationFailure { ErrorMessage = "err", }); // crashes
        // ThrowError("err"); // works
        // ThrowError(new ValidationFailure()); // crashes
        // ThrowError(new ValidationFailure { PropertyName = "prop", }); // works
        // ThrowError(new ValidationFailure { PropertyName = "prop", ErrorMessage = "err"}); // works  
    }
}

Expectation:
ThrowError(new ValidationFailure { ErrorMessage = "err" }); has the same behaviour as ThrowError("err");.
PropertyName/name just gets set to "generalErrors".

Stacktrace:

System.NullReferenceException: Object reference not set to an instance of an object.
         at FastEndpoints.ProblemDetails.Error.Comparer.GetHashCode(Error obj)
         at System.Collections.Generic.HashSet`1.AddIfNotPresent(T value, Int32& location)
         at System.Collections.Generic.HashSet`1.Add(T item)
         at FastEndpoints.ProblemDetails.Initialize(IReadOnlyList`1 failures, String instance, String traceId, Int32 statusCode)
         at FastEndpoints.ProblemDetails..ctor(IReadOnlyList`1 failures, String instance, String traceId, Int32 statusCode)
         at FastEndpoints.ProblemDetails.<>c.<.cctor>b__47_0(List`1 failures, HttpContext ctx, Int32 statusCode)
         at FastEndpoints.HttpResponseExtensions.SendErrorsAsync(HttpResponse rsp, List`1 failures, Int32 statusCode, JsonSerializerContext jsonSerializerContext, CancellationToken cancellation)
         at FastEndpoints.Endpoint`2.SendErrorsAsync(Int32 statusCode, CancellationToken cancellation)
         at FastEndpoints.Endpoint`2.<>c__DisplayClass0_0.<<ExecAsync>g__ValidationFailed|0>d.MoveNext()
      --- End of stack trace from previous location ---
         at FastEndpoints.Endpoint`2.ExecAsync(CancellationToken ct)
         at FastEndpoints.Endpoint`2.ExecAsync(CancellationToken ct)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
@dj-nitehawk
Copy link
Member

thanks for reporting...
fixed in v5.22.0.15-beta

@dj-nitehawk dj-nitehawk added bug Something isn't working fixed the bug has been squashed labels Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed the bug has been squashed
Development

No branches or pull requests

2 participants