Replaces ErrorOr library with a custom implementation.

This commit is contained in:
BinaryAlley committed 2026-08-14 03:04:28 -07:00
1 parent 8fe90a4dde
commit 3b772d68ca
436 files changed
+4234 -3922

No files matched your search

@@ -1,10 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Error representing that the operation could not be completed due to a conflict with the current state.
/// </summary>
/// <param name="Code">The error code that uniquely identifies this error type.</param>
/// <param name="Description">The human-readable description of the error.</param>
public record ConflictError(string Code, string Description) : Error
{
/// <summary>
/// Gets the type of this error.
/// </summary>
public override ErrorType Type => ErrorType.Conflict;
/// <summary>
/// Gets the error code that uniquely identifies this error type.
/// </summary>
public override string Code { get; } = Code;
/// <summary>
/// Gets the human-readable description of the error.
/// </summary>
public override string Description { get; } = Description;
}
+76 -45
View File
@@ -1,10 +1,19 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Represents an error that can be implicitly converted to a Results.
/// Represents an error that can be implicitly converted to a Result.
/// </summary>
public abstract record Error
{
/// <summary>
/// Gets the type of this error.
/// </summary>
public abstract ErrorType Type { get; }
/// <summary>
/// Gets the error code that uniquely identifies this error type.
/// </summary>
@@ -25,112 +34,134 @@ public abstract record Error
}
/// <summary>
/// Creates a new NotFoundError with the specified description.
/// Creates a new NotFoundError.
/// </summary>
/// <param name="code">The error code, defaults to "General.NotFound" when null.</param>
/// <param name="description">The human-readable description of the error.</param>
/// <returns>A new NotFoundError instance with code "NotFound".</returns>
public static NotFoundError NotFound(string description)
/// <returns>A new NotFoundError instance.</returns>
public static NotFoundError NotFound(string? code = null, string? description = null)
{
return new("NotFound", description);
return new(code ?? "General.NotFound", description ?? "A 'Not Found' error has occurred.");
}
/// <summary>
/// Creates a new InvalidOperationError with the specified description.
/// Creates a new InvalidOperationError.
/// </summary>
/// <param name="code">The error code, defaults to "General.InvalidOperation" when null.</param>
/// <param name="description">The human-readable description of the error.</param>
/// <returns>A new InvalidOperationError instance with code "InvalidOperation".</returns>
public static InvalidOperationError InvalidOperation(string description)
/// <returns>A new InvalidOperationError instance.</returns>
public static InvalidOperationError InvalidOperation(string? code = null, string? description = null)
{
return new("InvalidOperation", description);
return new(code ?? "General.InvalidOperation", description ?? "An invalid operation error has occurred.");
}
/// <summary>
/// Creates a new ForbiddenError with the specified description.
/// Creates a new ForbiddenError.
/// </summary>
/// <param name="code">The error code, defaults to "General.Forbidden" when null.</param>
/// <param name="description">The human-readable description of the error.</param>
/// <returns>A new ForbiddenError instance with code "Forbidden".</returns>
public static ForbiddenError Forbidden(string description)
/// <returns>A new ForbiddenError instance.</returns>
public static ForbiddenError Forbidden(string? code = null, string? description = null)
{
return new("Forbidden", description);
return new(code ?? "General.Forbidden", description ?? "A 'Forbidden' error has occurred.");
}
/// <summary>
/// Creates a new FailureError with the specified description.
/// Creates a new FailureError.
/// </summary>
/// <param name="code">The error code, defaults to "General.Failure" when null.</param>
/// <param name="description">The human-readable description of the error.</param>
/// <returns>A new FailureError instance with code "Failure".</returns>
public static FailureError Failure(string description)
/// <returns>A new FailureError instance.</returns>
public static FailureError Failure(string? code = null, string? description = null)
{
return new("Failure", description);
return new(code ?? "General.Failure", description ?? "A failure has occurred.");
}
/// <summary>
/// Creates a new ValidationError with the specified description.
/// Creates a new ValidationError.
/// </summary>
/// <param name="code">The error code, defaults to "General.Validation" when null.</param>
/// <param name="description">The human-readable description of the error.</param>
/// <returns>A new ValidationError instance with code "Validation".</returns>
public static ValidationError Validation(string description)
/// <returns>A new ValidationError instance.</returns>
public static ValidationError Validation(string? code = null, string? description = null)
{
return new("Validation", description);
return new(code ?? "General.Validation", description ?? "A validation error has occurred.");
}
/// <summary>
/// Creates a new ConflictError with the specified description.
/// Creates a new ConflictError.
/// </summary>
/// <param name="code">The error code, defaults to "General.Conflict" when null.</param>
/// <param name="description">The human-readable description of the error.</param>
/// <returns>A new ConflictError instance with code "Conflict".</returns>
public static ConflictError Conflict(string description)
/// <returns>A new ConflictError instance.</returns>
public static ConflictError Conflict(string? code = null, string? description = null)
{
return new("Conflict", description);
return new(code ?? "General.Conflict", description ?? "A conflict error has occurred.");
}
/// <summary>
/// Creates a new TimeoutError with the specified description.
/// Creates a new TimeoutError.
/// </summary>
/// <param name="code">The error code, defaults to "General.Timeout" when null.</param>
/// <param name="description">The human-readable description of the error.</param>
/// <returns>A new TimeoutError instance with code "Timeout".</returns>
public static TimeoutError Timeout(string description)
/// <returns>A new TimeoutError instance.</returns>
public static TimeoutError Timeout(string? code = null, string? description = null)
{
return new("Timeout", description);
return new(code ?? "General.Timeout", description ?? "The operation timed out.");
}
/// <summary>
/// Creates a new UnauthorizedError with the specified description.
/// Creates a new UnauthorizedError.
/// </summary>
/// <param name="code">The error code, defaults to "General.Unauthorized" when null.</param>
/// <param name="description">The human-readable description of the error.</param>
/// <returns>A new UnauthorizedError instance with code "Unauthorized".</returns>
public static UnauthorizedError Unauthorized(string description)
/// <returns>A new UnauthorizedError instance.</returns>
public static UnauthorizedError Unauthorized(string? code = null, string? description = null)
{
return new("Unauthorized", description);
return new(code ?? "General.Unauthorized", description ?? "An 'Unauthorized' error has occurred.");
}
/// <summary>
/// Creates a new InternalError with the specified description.
/// Creates a new UnexpectedError.
/// </summary>
/// <param name="code">The error code, defaults to "General.Unexpected" when null.</param>
/// <param name="description">The human-readable description of the error.</param>
/// <returns>A new InternalError instance with code "Internal".</returns>
public static InternalError Internal(string description)
/// <returns>A new UnexpectedError instance.</returns>
public static UnexpectedError Unexpected(string? code = null, string? description = null)
{
return new("Internal", description);
return new(code ?? "General.Unexpected", description ?? "An unexpected error has occurred.");
}
/// <summary>
/// Creates a new ResourceUnavailableError with the specified description.
/// Creates a new InternalError.
/// </summary>
/// <param name="code">The error code, defaults to "General.Internal" when null.</param>
/// <param name="description">The human-readable description of the error.</param>
/// <returns>A new ResourceUnavailableError instance with code "ResourceUnavailable".</returns>
public static ResourceUnavailableError ResourceUnavailable(string description)
/// <returns>A new InternalError instance.</returns>
public static InternalError Internal(string? code = null, string? description = null)
{
return new("ResourceUnavailable", description);
return new(code ?? "General.Internal", description ?? "An internal error has occurred.");
}
/// <summary>
/// Creates a new NotImplementedError with the specified description.
/// Creates a new ResourceUnavailableError.
/// </summary>
/// <param name="code">The error code, defaults to "General.ResourceUnavailable" when null.</param>
/// <param name="description">The human-readable description of the error.</param>
/// <returns>A new NotImplementedError instance with code "NotImplemented".</returns>
public static NotImplementedError NotImplemented(string description)
/// <returns>A new ResourceUnavailableError instance.</returns>
public static ResourceUnavailableError ResourceUnavailable(string? code = null, string? description = null)
{
return new("NotImplemented", description);
return new(code ?? "General.ResourceUnavailable", description ?? "The required resource is currently unavailable.");
}
/// <summary>
/// Creates a new NotImplementedError.
/// </summary>
/// <param name="code">The error code, defaults to "General.NotImplemented" when null.</param>
/// <param name="description">The human-readable description of the error.</param>
/// <returns>A new NotImplementedError instance.</returns>
public static NotImplementedError NotImplemented(string? code = null, string? description = null)
{
return new(code ?? "General.NotImplemented", description ?? "The requested functionality is not implemented.");
}
}
@@ -1,10 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Error representing that some operation failing.
/// </summary>
/// <param name="Code">The error code that uniquely identifies this error type.</param>
/// <param name="Description">The human-readable description of the error.</param>
public record FailureError(string Code, string Description) : Error
{
/// <summary>
/// Gets the type of this error.
/// </summary>
public override ErrorType Type => ErrorType.Failure;
/// <summary>
/// Gets the error code that uniquely identifies this error type.
/// </summary>
public override string Code { get; } = Code;
/// <summary>
/// Gets the human-readable description of the error.
/// </summary>
public override string Description { get; } = Description;
}
@@ -1,10 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Error representing that the operation is not allowed due to insufficient permissions or restrictions.
/// </summary>
/// <param name="Code">The error code that uniquely identifies this error type.</param>
/// <param name="Description">The human-readable description of the error.</param>
public record ForbiddenError(string Code, string Description) : Error
{
/// <summary>
/// Gets the type of this error.
/// </summary>
public override ErrorType Type => ErrorType.Forbidden;
/// <summary>
/// Gets the error code that uniquely identifies this error type.
/// </summary>
public override string Code { get; } = Code;
/// <summary>
/// Gets the human-readable description of the error.
/// </summary>
public override string Description { get; } = Description;
}
@@ -1,10 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Error representing that an unexpected internal error occurred.
/// </summary>
/// <param name="Code">The error code that uniquely identifies this error type.</param>
/// <param name="Description">The human-readable description of the error.</param>
public record InternalError(string Code, string Description) : Error
{
/// <summary>
/// Gets the type of this error.
/// </summary>
public override ErrorType Type => ErrorType.Unexpected;
/// <summary>
/// Gets the error code that uniquely identifies this error type.
/// </summary>
public override string Code { get; } = Code;
/// <summary>
/// Gets the human-readable description of the error.
/// </summary>
public override string Description { get; } = Description;
}
@@ -1,10 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Error representing that the operation is invalid in the current state or context.
/// </summary>
/// <param name="Code">The error code that uniquely identifies this error type.</param>
/// <param name="Description">The human-readable description of the error.</param>
public record InvalidOperationError(string Code, string Description) : Error
{
/// <summary>
/// Gets the type of this error.
/// </summary>
public override ErrorType Type => ErrorType.Unexpected;
/// <summary>
/// Gets the error code that uniquely identifies this error type.
/// </summary>
public override string Code { get; } = Code;
/// <summary>
/// Gets the human-readable description of the error.
/// </summary>
public override string Description { get; } = Description;
}
@@ -1,10 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Error representing that the requested resource or entity was not found.
/// </summary>
/// <param name="Code">The error code that uniquely identifies this error type.</param>
/// <param name="Description">The human-readable description of the error.</param>
public record NotFoundError(string Code, string Description) : Error
{
/// <summary>
/// Gets the type of this error.
/// </summary>
public override ErrorType Type => ErrorType.NotFound;
/// <summary>
/// Gets the error code that uniquely identifies this error type.
/// </summary>
public override string Code { get; } = Code;
/// <summary>
/// Gets the human-readable description of the error.
/// </summary>
public override string Description { get; } = Description;
}
@@ -1,10 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Error representing that the requested functionality is not implemented.
/// </summary>
/// <param name="Code">The error code that uniquely identifies this error type.</param>
/// <param name="Description">The human-readable description of the error.</param>
public record NotImplementedError(string Code, string Description) : Error
{
/// <summary>
/// Gets the type of this error.
/// </summary>
public override ErrorType Type => ErrorType.Unexpected;
/// <summary>
/// Gets the error code that uniquely identifies this error type.
/// </summary>
public override string Code { get; } = Code;
/// <summary>
/// Gets the human-readable description of the error.
/// </summary>
public override string Description { get; } = Description;
}
@@ -1,10 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Error representing that the required resource is currently unavailable.
/// </summary>
/// <param name="Code">The error code that uniquely identifies this error type.</param>
/// <param name="Description">The human-readable description of the error.</param>
public record ResourceUnavailableError(string Code, string Description) : Error
{
/// <summary>
/// Gets the type of this error.
/// </summary>
public override ErrorType Type => ErrorType.Unexpected;
/// <summary>
/// Gets the error code that uniquely identifies this error type.
/// </summary>
public override string Code { get; } = Code;
/// <summary>
/// Gets the human-readable description of the error.
/// </summary>
public override string Description { get; } = Description;
}
@@ -1,9 +1,9 @@
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Provides predefined success results for operations that don't return meaningful data.
/// Provides predefined success results for operations that don't return meaningful data, and factory methods for results.
/// </summary>
public static class Results
public static class Result
{
/// <summary>
/// Represents a successful operation.
@@ -24,4 +24,15 @@ public static class Results
/// Represents a successful deletion operation.
/// </summary>
public static Deleted Deleted { get; } = new();
/// <summary>
/// Creates a successful result wrapping the provided value.
/// </summary>
/// <typeparam name="TValue">The type of the value to wrap.</typeparam>
/// <param name="value">The value to wrap in a successful result.</param>
/// <returns>A successful result containing the provided value.</returns>
public static Result<TValue> From<TValue>(TValue value)
{
return Result<TValue>.Success(value);
}
}
@@ -1,3 +1,9 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
@@ -1,10 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Error representing that the operation timed out before completion.
/// </summary>
/// <param name="Code">The error code that uniquely identifies this error type.</param>
/// <param name="Description">The human-readable description of the error.</param>
public record TimeoutError(string Code, string Description) : Error
{
/// <summary>
/// Gets the type of this error.
/// </summary>
public override ErrorType Type => ErrorType.Unexpected;
/// <summary>
/// Gets the error code that uniquely identifies this error type.
/// </summary>
public override string Code { get; } = Code;
/// <summary>
/// Gets the human-readable description of the error.
/// </summary>
public override string Description { get; } = Description;
}
@@ -1,10 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Error representing that authentication is required or has failed.
/// </summary>
/// <param name="Code">The error code that uniquely identifies this error type.</param>
/// <param name="Description">The human-readable description of the error.</param>
public record UnauthorizedError(string Code, string Description) : Error
{
/// <summary>
/// Gets the type of this error.
/// </summary>
public override ErrorType Type => ErrorType.Unauthorized;
/// <summary>
/// Gets the error code that uniquely identifies this error type.
/// </summary>
public override string Code { get; } = Code;
/// <summary>
/// Gets the human-readable description of the error.
/// </summary>
public override string Description { get; } = Description;
}
@@ -0,0 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Error representing that an unexpected error occurred.
/// </summary>
/// <param name="Code">The error code that uniquely identifies this error type.</param>
/// <param name="Description">The human-readable description of the error.</param>
public record UnexpectedError(string Code, string Description) : Error
{
/// <summary>
/// Gets the type of this error.
/// </summary>
public override ErrorType Type => ErrorType.Unexpected;
/// <summary>
/// Gets the error code that uniquely identifies this error type.
/// </summary>
public override string Code { get; } = Code;
/// <summary>
/// Gets the human-readable description of the error.
/// </summary>
public override string Description { get; } = Description;
}
@@ -1,10 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
#endregion
namespace Lumina.Domain.Common.Primitives;
/// <summary>
/// Error representing that the input or data failed validation rules.
/// </summary>
/// <param name="Code">The error code that uniquely identifies this error type.</param>
/// <param name="Description">The human-readable description of the error.</param>
public record ValidationError(string Code, string Description) : Error
{
/// <summary>
/// Gets the type of this error.
/// </summary>
public override ErrorType Type => ErrorType.Validation;
/// <summary>
/// Gets the error code that uniquely identifies this error type.
/// </summary>
public override string Code { get; } = Code;
/// <summary>
/// Gets the human-readable description of the error.
/// </summary>
public override string Description { get; } = Description;
}