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

@@ -0,0 +1,33 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Domain.Common.Errors;
/// <summary>
/// File management error types.
/// </summary>
public static partial class Errors
{
public static class FileSystemManagement
{
public static Error ParentNodeCannotBeNull => Error.Failure(description: nameof(ParentNodeCannotBeNull));
public static Error PathMustBeMaximum260CharactersLong => Error.Failure(description: nameof(PathMustBeMaximum260CharactersLong));
public static Error FileCopyError => Error.Failure(description: nameof(FileCopyError));
public static Error FileMoveError => Error.Failure(description: nameof(FileMoveError));
public static Error DirectoryCopyError => Error.Failure(description: nameof(DirectoryCopyError));
public static Error DirectoryMoveError => Error.Failure(description: nameof(DirectoryMoveError));
public static Error FileNotFound => Error.NotFound(description: nameof(FileNotFound));
public static Error InvalidPath => Error.Validation(description: nameof(InvalidPath));
public static Error PathCannotBeEmpty => Error.Validation(description: nameof(PathCannotBeEmpty));
public static Error ExtensionCannotBeEmpty => Error.Validation(description: nameof(ExtensionCannotBeEmpty));
public static Error StreamIdCannotBeEmpty => Error.Validation(description: nameof(StreamIdCannotBeEmpty));
public static Error CodecCannotBeEmpty => Error.Validation(description: nameof(CodecCannotBeEmpty));
public static Error BitrateMustBeAPositiveNumber => Error.Validation(description: nameof(BitrateMustBeAPositiveNumber));
public static Error CannotNavigateUp => Error.Failure(description: nameof(CannotNavigateUp));
public static Error NameCannotBeEmpty => Error.Validation(description: nameof(NameCannotBeEmpty));
public static Error FileAlreadyExists => Error.Conflict(description: nameof(FileAlreadyExists));
public static Error DirectoryNotFound => Error.NotFound(description: nameof(DirectoryNotFound));
public static Error DirectoryAlreadyExists => Error.Conflict(description: nameof(DirectoryAlreadyExists));
}
}
@@ -0,0 +1,27 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Domain.Common.Errors;
/// <summary>
/// Media Library error types.
/// </summary>
public static partial class Errors
{
public static class Library
{
public static Error CannotScanLockedLibrary => Error.Forbidden(description: nameof(CannotScanLockedLibrary));
public static Error CannotScanDisabledLibrary => Error.Forbidden(description: nameof(CannotScanDisabledLibrary));
public static Error LibraryIdCannotBeEmpty => Error.Validation(description: nameof(LibraryIdCannotBeEmpty));
public static Error LibraryAlreadyExists => Error.Conflict(description: nameof(LibraryAlreadyExists));
public static Error LibraryNotFound => Error.NotFound(description: nameof(LibraryNotFound));
public static Error LibraryTypeCannotBeNull => Error.Validation(description: nameof(LibraryTypeCannotBeNull));
public static Error CoverFileMustBeAnImage => Error.Validation(description: nameof(CoverFileMustBeAnImage));
public static Error UnknownLibraryType => Error.Unexpected(description: nameof(UnknownLibraryType));
public static Error PathsListCannotBeNull => Error.Validation(description: nameof(PathsListCannotBeNull));
public static Error PathsListCannotBeEmpty => Error.Validation(description: nameof(PathsListCannotBeEmpty));
public static Error TitleCannotBeEmpty => Error.Validation(description: nameof(TitleCannotBeEmpty));
public static Error TitleMustBeMaximum255CharactersLong => Error.Validation(description: nameof(TitleMustBeMaximum255CharactersLong));
}
}
@@ -0,0 +1,31 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Domain.Common.Errors;
/// <summary>
/// Media Library Scan error types.
/// </summary>
public static partial class Errors
{
public static class LibraryScanning
{
public static Error LibraryScanIdCannotBeEmpty => Error.Validation(description: nameof(LibraryScanIdCannotBeEmpty));
public static Error CanOnlyStartPendingScans => Error.Forbidden(description: nameof(CanOnlyStartPendingScans));
public static Error CanOnlyCompleteRunningScans => Error.Forbidden(description: nameof(CanOnlyCompleteRunningScans));
public static Error CanOnlyCancelRunningScans => Error.Forbidden(description: nameof(CanOnlyCancelRunningScans));
public static Error CanOnlyFailRunningScans => Error.Forbidden(description: nameof(CanOnlyFailRunningScans));
public static Error ScanIdCannotBeEmpty => Error.Validation(description: nameof(ScanIdCannotBeEmpty));
public static Error LibraryScanAlreadyExists => Error.Conflict(description: nameof(LibraryScanAlreadyExists));
public static Error LibraryAlreadyBeingScanned => Error.Forbidden(description: nameof(LibraryAlreadyBeingScanned));
public static Error LibraryScanNotFound => Error.NotFound(description: nameof(LibraryScanNotFound));
public static Error TotalScanJobItemsCountMustBePositive => Error.Validation(description: nameof(TotalScanJobItemsCountMustBePositive));
public static Error TotalScanJobsCountMustBePositive => Error.Validation(description: nameof(TotalScanJobsCountMustBePositive));
public static Error CompletedScanJobItemsCountMustBePositive => Error.Validation(description: nameof(CompletedScanJobItemsCountMustBePositive));
public static Error CompletedScanJobsCountMustBePositive => Error.Validation(description: nameof(CompletedScanJobsCountMustBePositive));
public static Error CompletedScanJobItemsCountCantExceedTotalScanJobItemsCount => Error.Validation(description: nameof(CompletedScanJobItemsCountCantExceedTotalScanJobItemsCount));
public static Error CompletedScanJobsCountCantExceedTotalScanJobsCount => Error.Validation(description: nameof(CompletedScanJobsCountCantExceedTotalScanJobsCount));
public static Error ScanJobCurrentOperationCannotBeEmpty => Error.Validation(description: nameof(ScanJobCurrentOperationCannotBeEmpty));
}
}
@@ -0,0 +1,25 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Domain.Common.Errors;
/// <summary>
/// Media contributor error types.
/// </summary>
public static partial class Errors
{
public static class MediaContributor
{
public static Error ContributorsListCannotBeNull => Error.Validation(description: nameof(ContributorsListCannotBeNull));
public static Error ContributorNameCannotBeEmpty => Error.Validation(description: nameof(ContributorNameCannotBeEmpty));
public static Error ContributorDisplayNameCannotBeEmpty => Error.Validation(description: nameof(ContributorDisplayNameCannotBeEmpty));
public static Error ContributorDisplayNameMustBeMaximum100CharactersLong => Error.Validation(description: nameof(ContributorDisplayNameMustBeMaximum100CharactersLong));
public static Error ContributorLegalNameMustBeMaximum100CharactersLong => Error.Validation(description: nameof(ContributorLegalNameMustBeMaximum100CharactersLong));
public static Error RoleNameCannotBeEmpty => Error.Validation(description: nameof(RoleNameCannotBeEmpty));
public static Error RoleNameMustBeMaximum50CharactersLong => Error.Validation(description: nameof(RoleNameMustBeMaximum50CharactersLong));
public static Error RoleCategoryCannotBeEmpty => Error.Validation(description: nameof(RoleCategoryCannotBeEmpty));
public static Error RoleCategoryMustBeMaximum50CharactersLong => Error.Validation(description: nameof(RoleCategoryMustBeMaximum50CharactersLong));
public static Error ContributorRoleCannotBeNull => Error.Validation(description: nameof(ContributorRoleCannotBeNull));
}
}
@@ -0,0 +1,46 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Domain.Common.Errors;
/// <summary>
/// Metadata error types.
/// </summary>
public static partial class Errors
{
public static class Metadata
{
public static Error MetadataCannotBeNull => Error.Validation(description: nameof(MetadataCannotBeNull));
public static Error TitleCannotBeEmpty => Error.Validation(description: nameof(TitleCannotBeEmpty));
public static Error TitleMustBeMaximum255CharactersLong => Error.Validation(description: nameof(TitleMustBeMaximum255CharactersLong));
public static Error OriginalTitleMustBeMaximum255CharactersLong => Error.Validation(description: nameof(OriginalTitleMustBeMaximum255CharactersLong));
public static Error DescriptionMustBeMaximum2000CharactersLong => Error.Validation(description: nameof(DescriptionMustBeMaximum2000CharactersLong));
public static Error GenresListCannotBeNull => Error.Validation(description: nameof(GenresListCannotBeNull));
public static Error GenreNameCannotBeEmpty => Error.Validation(description: nameof(GenreNameCannotBeEmpty));
public static Error GenreNameMustBeMaximum50CharactersLong => Error.Validation(description: nameof(GenreNameMustBeMaximum50CharactersLong));
public static Error TagsListCannotBeNull => Error.Validation(description: nameof(TagsListCannotBeNull));
public static Error TagNameCannotBeEmpty => Error.Validation(description: nameof(TagNameCannotBeEmpty));
public static Error TagNameMustBeMaximum50CharactersLong => Error.Validation(description: nameof(TagNameMustBeMaximum50CharactersLong));
public static Error LanguageCodeCannotBeEmpty => Error.Validation(description: nameof(LanguageCodeCannotBeEmpty));
public static Error LanguageNameCannotBeEmpty => Error.Validation(description: nameof(LanguageNameCannotBeEmpty));
public static Error LanguageCodeMustBe2CharactersLong => Error.Validation(description: nameof(LanguageCodeMustBe2CharactersLong));
public static Error LanguageNameMustBeMaximum50CharactersLong => Error.Validation(description: nameof(LanguageNameMustBeMaximum50CharactersLong));
public static Error LanguageNativeNameMustBeMaximum50CharactersLong => Error.Validation(description: nameof(LanguageNativeNameMustBeMaximum50CharactersLong));
public static Error OriginalReleaseYearMustBeBetween1And9999 => Error.Validation(description: nameof(OriginalReleaseYearMustBeBetween1And9999));
public static Error ReReleaseYearMustBeBetween1And9999 => Error.Validation(description: nameof(ReReleaseYearMustBeBetween1And9999));
public static Error ReReleaseYearCannotBeEarlierThanOriginalReleaseYear => Error.Validation(description: nameof(ReReleaseYearCannotBeEarlierThanOriginalReleaseYear));
public static Error CountryCodeMustBe2CharactersLong => Error.Validation(description: nameof(CountryCodeMustBe2CharactersLong));
public static Error ReleaseVersionMustBeMaximum50CharactersLong => Error.Validation(description: nameof(ReleaseVersionMustBeMaximum50CharactersLong));
public static Error OriginalReleaseDateAndYearMustMatch => Error.Validation(description: nameof(OriginalReleaseDateAndYearMustMatch));
public static Error ReReleaseDateAndYearMustMatch => Error.Validation(description: nameof(ReReleaseDateAndYearMustMatch));
public static Error ReReleaseDateCannotBeEarlierThanOriginalReleaseDate => Error.Validation(description: nameof(ReReleaseDateCannotBeEarlierThanOriginalReleaseDate));
public static Error ReleaseInfoCannotBeNull => Error.Validation(description: nameof(ReleaseInfoCannotBeNull));
public static Error RatingValueMustBePositive => Error.Validation(description: nameof(RatingValueMustBePositive));
public static Error RatingMaxValueMustBePositive => Error.Validation(description: nameof(RatingMaxValueMustBePositive));
public static Error RatingValueCannotBeGreaterThanMaxValue => Error.Validation(description: nameof(RatingValueCannotBeGreaterThanMaxValue));
public static Error RatingVoteCountMustBePositive => Error.Validation(description: nameof(RatingVoteCountMustBePositive));
public static Error RatingsListCannotBeNull => Error.Validation(description: nameof(RatingsListCannotBeNull));
public static Error InvalidIsoCode => Error.Validation(description: nameof(InvalidIsoCode));
}
}
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Domain.Common.Errors;
/// <summary>
/// Domain permission related error types.
/// </summary>
public static partial class Errors
{
public static class Permission
{
public static Error UnauthorizedAccess => Error.Failure(description: nameof(UnauthorizedAccess));
}
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Domain.Common.Errors;
/// <summary>
/// Plugin error types.
/// </summary>
public static partial class Errors
{
public static class Plugins
{
public static Error PluginNotFound => Error.NotFound(description: nameof(PluginNotFound));
public static Error PluginIdCannotBeEmpty => Error.Validation(description: nameof(PluginIdCannotBeEmpty));
public static Error PluginSettingsCannotBeNull => Error.Validation(description: nameof(PluginSettingsCannotBeNull));
public static Error LibraryIdCannotBeEmpty => Error.Validation(description: nameof(LibraryIdCannotBeEmpty));
public static Error PluginIdsListCannotBeNull => Error.Validation(description: nameof(PluginIdsListCannotBeNull));
public static Error PluginIdsListCannotBeEmpty => Error.Validation(description: nameof(PluginIdsListCannotBeEmpty));
public static Error LibraryMetadataProviderConfigurationNotFound => Error.NotFound(description: nameof(LibraryMetadataProviderConfigurationNotFound));
}
}
@@ -0,0 +1,17 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Domain.Common.Errors;
/// <summary>
/// Domain thumbnails related error types.
/// </summary>
public static partial class Errors
{
public static class Thumbnails
{
public static Error NoThumbnail => Error.Failure(description: nameof(NoThumbnail));
public static Error ImageQualityMustBeBetweenZeroAndOneHundred => Error.Validation(description: nameof(ImageQualityMustBeBetweenZeroAndOneHundred));
}
}
@@ -0,0 +1,18 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Domain.Common.Errors;
/// <summary>
/// Users error types.
/// </summary>
public static partial class Errors
{
public static class Users
{
public static Error UserAlreadyExists => Error.Conflict(description: nameof(UserAlreadyExists));
public static Error UserDoesNotExist => Error.NotFound(description: nameof(UserDoesNotExist));
public static Error UserIdCannotBeEmpty => Error.Validation(description: nameof(UserIdCannotBeEmpty));
}
}
@@ -0,0 +1,42 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Domain.Common.Errors;
/// <summary>
/// Written content error types.
/// </summary>
public static partial class Errors
{
public static class WrittenContent
{
public static Error BookAlreadyExists => Error.Conflict(description: nameof(BookAlreadyExists));
public static Error IsbnValueCannotBeEmpty => Error.Validation(description: nameof(IsbnValueCannotBeEmpty));
public static Error IsbnListCannotBeNull => Error.Validation(description: nameof(IsbnListCannotBeNull));
public static Error InvalidIsbn10Format => Error.Validation(description: nameof(InvalidIsbn10Format));
public static Error InvalidIsbn13Format => Error.Validation(description: nameof(InvalidIsbn13Format));
public static Error UnknownIsbnFormat => Error.Unexpected(description: nameof(UnknownIsbnFormat));
public static Error TheBookIsAlreadyInTheSeries => Error.Forbidden(description: nameof(TheBookIsAlreadyInTheSeries));
public static Error TheBookIsNotInTheSeries => Error.Forbidden(description: nameof(TheBookIsNotInTheSeries));
public static Error AsinMustBe10CharactersLong => Error.Validation(description: nameof(AsinMustBe10CharactersLong));
public static Error GoodreadsIdMustBeNumeric => Error.Validation(description: nameof(GoodreadsIdMustBeNumeric));
public static Error InvalidLccnFormat => Error.Validation(description: nameof(InvalidLccnFormat));
public static Error InvalidOclcFormat => Error.Validation(description: nameof(InvalidOclcFormat));
public static Error InvalidOpenLibraryId => Error.Validation(description: nameof(InvalidOpenLibraryId));
public static Error LibraryThingIdMustBeMaximum50CharactersLong => Error.Validation(description: nameof(LibraryThingIdMustBeMaximum50CharactersLong));
public static Error GoogleBooksIdMustBe12CharactersLong => Error.Validation(description: nameof(GoogleBooksIdMustBe12CharactersLong));
public static Error InvalidGoogleBooksIdFormat => Error.Validation(description: nameof(InvalidGoogleBooksIdFormat));
public static Error BarnesAndNoblesIdMustBe10CharactersLong => Error.Validation(description: nameof(BarnesAndNoblesIdMustBe10CharactersLong));
public static Error InvalidBarnesAndNoblesIdFormat => Error.Validation(description: nameof(InvalidBarnesAndNoblesIdFormat));
public static Error InvalidAppleBooksIdFormat => Error.Validation(description: nameof(InvalidAppleBooksIdFormat));
public static Error PublisherMustBeMaximum100CharactersLong => Error.Validation(description: nameof(PublisherMustBeMaximum100CharactersLong));
public static Error PageCountMustBeGreaterThanZero => Error.Validation(description: nameof(PageCountMustBeGreaterThanZero));
public static Error UnknownBookFormat => Error.Validation(description: nameof(UnknownBookFormat));
public static Error EditionMustBeMaximum50CharactersLong => Error.Validation(description: nameof(EditionMustBeMaximum50CharactersLong));
public static Error VolumeNumberMustBeGreaterThanZero => Error.Validation(description: nameof(VolumeNumberMustBeGreaterThanZero));
public static Error BookLibraryCannotBeNull => Error.Validation(description: nameof(BookLibraryCannotBeNull));
public static Error BookPathCannotBeEmpty => Error.Validation(description: nameof(BookPathCannotBeEmpty));
public static Error BookNotFound => Error.NotFound(description: nameof(BookNotFound));
}
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
#endregion
@@ -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;
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -33,12 +32,12 @@ public class Genre : ValueObject
/// </summary>
/// <param name="name">The value of the genre.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Genre"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Genre"/>, or an error message.
/// </returns>
public static ErrorOr<Genre> Create(string? name)
public static Result<Genre> Create(string? name)
{
if (string.IsNullOrWhiteSpace(name))
return Errors.Metadata.GenreNameCannotBeEmpty;
return Errors.Errors.Metadata.GenreNameCannotBeEmpty;
return new Genre(name);
}
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Errors;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -50,16 +50,16 @@ public class LanguageInfo : ValueObject
/// <param name="languageName">The full name of the language in English.</param>
/// <param name="nativeName">The optional native name of the language.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="LanguageInfo"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="LanguageInfo"/>, or an error message.
/// </returns>
public static ErrorOr<LanguageInfo> Create(string? languageCode, string? languageName, Optional<string> nativeName)
public static Result<LanguageInfo> Create(string? languageCode, string? languageName, Optional<string> nativeName)
{
if (string.IsNullOrWhiteSpace(languageCode))
return Errors.Metadata.LanguageCodeCannotBeEmpty;
return Errors.Errors.Metadata.LanguageCodeCannotBeEmpty;
if (string.IsNullOrWhiteSpace(languageName))
return Errors.Metadata.LanguageNameCannotBeEmpty;
return Errors.Errors.Metadata.LanguageNameCannotBeEmpty;
if (languageCode.Length != 2)
return Errors.Metadata.InvalidIsoCode;
return Errors.Errors.Metadata.InvalidIsoCode;
return new LanguageInfo(languageCode, languageName, nativeName);
}
@@ -1,11 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Lumina.Domain.SharedKernel.Common.Errors;
#endregion
namespace Lumina.Domain.Common.ValueObjects.Metadata;
@@ -82,9 +80,9 @@ public class ReleaseInfo : ValueObject
/// <param name="releaseCountry">The optional country or region of release.</param>
/// <param name="releaseVersion">The optional release version or edition.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="ReleaseInfo"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="ReleaseInfo"/>, or an error message.
/// </returns>
public static ErrorOr<ReleaseInfo> Create(
public static Result<ReleaseInfo> Create(
Optional<DateOnly> originalReleaseDate,
Optional<int> originalReleaseYear,
Optional<DateOnly> reReleaseDate,
@@ -93,13 +91,13 @@ public class ReleaseInfo : ValueObject
Optional<string> releaseVersion)
{
if (originalReleaseDate.HasValue && originalReleaseYear.HasValue && originalReleaseDate.Value.Year != originalReleaseYear.Value)
return Errors.Metadata.OriginalReleaseDateAndYearMustMatch;
return Errors.Errors.Metadata.OriginalReleaseDateAndYearMustMatch;
if (reReleaseDate.HasValue && reReleaseYear.HasValue && reReleaseDate.Value.Year != reReleaseYear.Value)
return Errors.Metadata.ReReleaseDateAndYearMustMatch;
return Errors.Errors.Metadata.ReReleaseDateAndYearMustMatch;
if (originalReleaseDate.HasValue && reReleaseDate.HasValue && originalReleaseDate.Value > reReleaseDate.Value)
return Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate;
return Errors.Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate;
if (originalReleaseYear.HasValue && reReleaseYear.HasValue && originalReleaseYear.Value > reReleaseYear.Value)
return Errors.Metadata.ReReleaseYearCannotBeEarlierThanOriginalReleaseYear;
return Errors.Errors.Metadata.ReReleaseYearCannotBeEarlierThanOriginalReleaseYear;
return new ReleaseInfo(originalReleaseDate, originalReleaseYear, reReleaseDate, reReleaseYear, releaseCountry, releaseVersion);
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -33,12 +33,12 @@ public class Tag : ValueObject
/// </summary>
/// <param name="name">The value of the tag.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Tag"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Tag"/>, or an error message.
/// </returns>
public static ErrorOr<Tag> Create(string? name)
public static Result<Tag> Create(string? name)
{
if (string.IsNullOrWhiteSpace(name))
return Errors.Metadata.TagNameCannotBeEmpty;
return Errors.Errors.Metadata.TagNameCannotBeEmpty;
return new Tag(name);
}