LightResults icon indicating copy to clipboard operation
LightResults copied to clipboard

Broken example code in docs

Open Redplcs opened this issue 8 months ago • 1 comments

I just wanted to implement custom error for validation and I've checked your docs, but found out that it's not working. I'm talking to:

public sealed class HttpError : Error
{
    public HttpError(HttpStatusCode statusCode)
        : base("An HTTP error occured.", ("StatusCode", statusCode))
    {
    }
}

Here's the base ctor receives tuple for status code, but this argument receives only IReadOnlyDictionary<string, object>. Tuple cannot be converted into dictionary

Image

Link: https://jscarle.github.io/LightResults/docs/getting-started.html#custom-errors

Redplcs avatar Apr 22 '25 15:04 Redplcs

Maybe add new constructor that receives those tuples with params keyword that will be converted to dictionary?

Something like:

public Error(string message, params (string key, object value)[] metadata) : this(message, metadata.ToDictionary(x => x.key, x => x.value))

Even better: Change IReadOnlyDictionary<string, object> into IEnumerable<KeyValuePair<string, object>> to allow passing arrays instead of dictionaries to reduce allocations

Redplcs avatar Apr 22 '25 15:04 Redplcs

Image

also same

enricoroselino avatar Jun 02 '25 03:06 enricoroselino

@enricoroselino this package just don't updating. i migrated into ardalis' results instead. there is so much issues with this package. it's just don't ready to be used in production.

for example, pattern matching just don't work, because it has IsFailure/IsSuccess methods, instead of properties. To get value, you somehow need to call one of those methods and get value from out parameter. we have IActionableResult generic interface to instantiate result object instead of relying on reflection and this is great idea, but this just don't work, because you can't pass this into mediatr pipelines. mediatr just ignores this pipeline, because it can't match generic types. having better performance is not that worth than my headache with this package

Redplcs avatar Jun 02 '25 06:06 Redplcs

v9.0.3 has been published which add this and other meta data overloads.

jscarle avatar Jun 13 '25 22:06 jscarle