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

Potential misuse #102

Closed
md-redwan-hossain opened this issue May 5, 2024 · 5 comments
Closed

Potential misuse #102

md-redwan-hossain opened this issue May 5, 2024 · 5 comments

Comments

@md-redwan-hossain
Copy link

The current API allows the following which is not the intended use.

public ErrorOr<string> SendMessage()
{
    return new ErrorOr<string>();
}

It must be like this. However the API does not enforces it because struct must have a default constructor.

public ErrorOr<string> SendMessage()
{
    return "Hello";
}
@amantinband
Copy link
Owner

Thanks Hossain, that's a good point, but as you said, there isn't much we can do about this. I don't want to give up on ErrorOr being a struct since it doesn't allocate memory

@md-redwan-hossain
Copy link
Author

you can throw an error if the default constructor is called like the following, this will at least inform the consumer about the misuse.

public ErrorOr()
{
    throw new InvalidOperationException("Invoking Parameterless constructor is not allowed.");
}

@amantinband
Copy link
Owner

added as part of #105

@amantinband
Copy link
Owner

will be available as part of ErrorOr 3.x

@grant-ssi
Copy link

grant-ssi commented Aug 12, 2024

Note: This went out with 2.1.0 not 3.x. with #106

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

3 participants