-
Notifications
You must be signed in to change notification settings - Fork 107
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
Change the Status to Failed when any ValidationError is added to the Result. #161
Comments
Error is meant for exceptions typically, so if you add any validation errors I would expect the status to update to I'd be open to changing the behavior to that when adding a validation error the status changes to invalid, but I'm also not sure the current design will easily support that. I unfortunately broke my own advice and did not encapsulate the validation errors property - it's just an exposed To implement this change we would need to:
// Result.cs currently
public List<ValidationError> ValidationErrors { get; protected set; } = new List<ValidationError>(); Does that make sense and do you see a simpler way to do it? |
I was hard thinking about this in the last days and I always ended-up asking myself: Why I can change the 1 Only allow the user to instantiate it from the static constructors
PROS
CONS
2 Allow the user to instantiate it the way he likes
PROS
CONS
I really like the option 2 and I'm working to get it work like described here. PS: As I don't know the library in deep, and I don't know how breaking this second option would be. Right now my implementation does not break any test of the solution. |
Auto-evaluatie the Status property when Errors ou ValidationErrors are added to the result. It only works when teh result is created as Ok(), Error() ou Invalid()
I believe ValidationErrors shouldn't be exposed as a var successResult = Result.Success();
var validationErrors = successResult.ValidationErrors.ToList();
validationErrors.Add(new ValidationError { Identifier = "Foo", ErrorMessage = "Invalid Foo for some reason" });
var invalidResult = Result.Invalid(validationErrors); This prevents an existing Edit: |
I agree with your opinion, it is somehow what I described in "option 1" above. Like I said, this design is less flexible and restricts the way the user interact with the lib, but it is very straightforward (which is good). I do not fully agree with you when you say:
We can prevent this corrupted state with proper coding and automated testing like I did in the PR. Also, I read the article you mentioned and, from my understanding, it is more focused in Domain Driven Design which it is an effective way to design large and complex business rules and, "maybe" not so good to design a utility library as Result. Current SituationRight now the lib allows editing the
Both are breaking changes |
I think it was a design error of mine to expose |
Ok. Also, please reject the previous PR. |
Oops I forgot about this conversation and took in that PR, but we will make another PR here soon to fix everything up. |
I'm new using the Result so, first of all: congratulation and thanks for this amazing lib.
I like to develop my methods using the following pattern:
Seems like the Result don't like this approach because it forces me to define the Status at the creation of the Result, like so:
Result<Customer> result = Result.Success(customer);
Result<Customer> result = Result.Error("Some Error");
Result<Customer> result = Result.Invalid(new ValidationError("Some Error"));
Although, I tried to follow the pattern and discovered that I can instantiate the Result without defining the Status using
new Result(...)
but I found a "strange" behavior, here is the code:I don't know if this is a bug but it would be more concise if the Status get changed to something like
Invalid
ouError
when anyValidationError
is added to the Result.Is it possible or plausible?
The text was updated successfully, but these errors were encountered: