Summary
Result.Failure(ResultStatus resultStatus, string? errorMessage = null) currently accepts any ResultStatus, including success statuses (Success, Created, NoContent). That contradicts the method name and intent.
Why
Callers can accidentally create a "failure" result that reports success (IsSuccess == true), which is confusing and error-prone.
Proposed change
- Validate that
resultStatus is a non-success status before creating the result
- Throw a clear exception (or otherwise reject) when a success status is passed
- Add/update unit tests for valid and invalid inputs
Context
Feedback from community code review.
Reported by
Thanks to Omid Rezaei Nejad for reporting this.
Summary
Result.Failure(ResultStatus resultStatus, string? errorMessage = null)currently accepts anyResultStatus, including success statuses (Success,Created,NoContent). That contradicts the method name and intent.Why
Callers can accidentally create a "failure" result that reports success (
IsSuccess == true), which is confusing and error-prone.Proposed change
resultStatusis a non-success status before creating the resultContext
Feedback from community code review.
Reported by
Thanks to Omid Rezaei Nejad for reporting this.