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

Draft: Migrate from Errors to Exceptions for invalid use of library #105

Merged
merged 13 commits into from
May 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: add additional exception XML comments to ErrorOr<TValue>
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
  • Loading branch information
feO2x committed May 9, 2024
commit 61d1540b30697afe8f8483c4eae0d46a3e44a3bd
4 changes: 4 additions & 0 deletions src/ErrorOr/ErrorOr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace ErrorOr;
/// <summary>
/// Prevents a default <see cref="ErrorOr"/> struct from being created.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown when this method is called.</exception>
public ErrorOr()
{
throw new InvalidOperationException("Default construction of ErrorOr<TValue> is invalid. Please use provided factory methods to instantiate.");
Expand Down Expand Up @@ -46,6 +47,7 @@ private ErrorOr(TValue value)
/// <summary>
/// Gets the list of errors. If the state is not error, the list will contain a single error representing the state.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown when no errors are present.</exception>
public List<Error> Errors => IsError ? _errors : throw new InvalidOperationException("The Errors property cannot be accessed when no errors have been recorded. Check IsError before accessing Errors.");

/// <summary>
Expand All @@ -56,6 +58,7 @@ private ErrorOr(TValue value)
/// <summary>
/// Gets the value.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown when no value is present.</exception>
public TValue Value
{
get
Expand All @@ -72,6 +75,7 @@ public TValue Value
/// <summary>
/// Gets the first error.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown when no errors are present.</exception>
public Error FirstError
{
get
Expand Down