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

Value throws an InvalidOperationException after any call of .WithError() #199

Open
Ewerton opened this issue Jan 26, 2024 · 1 comment
Open

Comments

@Ewerton
Copy link

Ewerton commented Jan 26, 2024

Here are the steps to reproduce the behaviour.

public static void Test()
{
    Result<Customer> result = Result.Ok(new Customer() { Name = "Name", Email = "some@email.com"});

    var valueBefore = result.Value; // This works. The Value is not null

    result.WithError(new Error("Some Error"));

    var valueAfter = result.Value; // This will throw a exception: System.InvalidOperationException: 'Result is in status failed. Value is not set. Having: Error with Message='Some Error''
}
@Kilazur
Copy link

Kilazur commented Jan 29, 2024

This is intended behavior. By design, you're not supposed to access the value of a failed result.

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