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

Result created using Result.Fail with empty error list becomes a success #227

Open
sandord opened this issue Dec 16, 2024 · 2 comments
Open

Comments

@sandord
Copy link

sandord commented Dec 16, 2024

Perhaps rather naively, I'd expect the following code to either fail at runtime or the assertion to succeed.

var result = Result.Fail(new List<Error>())
result.IsFailed.Should().BeTrue();

But result.IsFailed turns out to be false, which seems a bit weird to me for an object that was created with Result.Fail().

Is it supposed to work like this?

@Feijo
Copy link

Feijo commented Dec 19, 2024

It's because the list of errors is empty, which is probably assumed to not have any errors.

The examples below work fine:

var result = Result.Fail(new List<Error> { new Error("") });
result.IsFailed.Should().BeTrue();

var result = Result.Fail(new List<string> { "" });
result.IsFailed.Should().BeTrue();

@sandord
Copy link
Author

sandord commented Dec 19, 2024

Sure, I understand that. But "a failure without errors is not a failure" sounds illogical to me. Logic dictates that a failure with no errors cannot exist because it is not a failure at all, since there are no errors in it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants