-
Notifications
You must be signed in to change notification settings - Fork 94
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
Draft: Migrate from Errors to Exceptions for invalid use of library #105
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #105 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 18 18
Lines 423 435 +12
Branches 49 54 +5
=========================================
+ Hits 423 435 +12 ☔ View full report in Codecov by Sentry. |
Hey Amichai, I've reviewed your code and created a new PR with suggested changes. I still have one question: would we allow public static implicit operator ErrorOr<TValue>(TValue value)
{
return new ErrorOr<TValue>(value);
} to public static implicit operator ErrorOr<TValue>(TValue value)
{
if (value is null)
{
throw new ArgumentNullException(nameof(value));
}
return new ErrorOr<TValue>(value);
} The reason behind this is the following: users of our library might have I'm interested in your opinion on this. |
This change saves us 8 bits in the ErrorOr<TValue> struct which leads to less execution time when an instance is copied by value. As the struct is now properly encapsulated from a Design by Contract point of view, I simply choose _errors being null as the indicator for errors not being present. Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
Instead of instantiating a new list every time ErrorsOrEmptyList is called with no errors being present, I reused a cached empty list. I also removed the unnecessary null-forgiving operators (the compiler uses the MemberNotNullWhenAttribute on IsError to verify that we checked for null beforehand). Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
The Value property is now properly encapsulated. When errors are present, the property getter will throw, similar to other properties like Errors or FirstError. Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
When clients have <Nullable> turned off, the C# compiler won't hint that null shouldn't be passed as the errors array/list. By explicitly checking for null, we eliminate these error cases. Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
… passed Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
We could also ask the community if they ever want |
Exceptions for invalid use - review and extensions
Yeah let's make this more strict as well. In any case this will all be introduced in a new major version. I think your suggestion is a better design. |
Yep, you are right. These are breaking changes, so we need to bump up to version 3. |
No description provided.