PlopyBlopy.FluentResults.Errors
1.0.7
dotnet add package PlopyBlopy.FluentResults.Errors --version 1.0.7
NuGet\Install-Package PlopyBlopy.FluentResults.Errors -Version 1.0.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PlopyBlopy.FluentResults.Errors" Version="1.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PlopyBlopy.FluentResults.Errors" Version="1.0.7" />
<PackageReference Include="PlopyBlopy.FluentResults.Errors" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PlopyBlopy.FluentResults.Errors --version 1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PlopyBlopy.FluentResults.Errors, 1.0.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=PlopyBlopy.FluentResults.Errors&version=1.0.7
#tool nuget:?package=PlopyBlopy.FluentResults.Errors&version=1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Error Handling Library Based on FluentResults
This library extends FluentResults by introducing a system of typed errors with predefined metadata structures for common scenarios. It implements the "Result-based error handling" pattern with enhanced semantics and error granularity.
Key Features
Standardized Error Types
Includes ready-to-use implementations for common cases:ValidationError
— Object validation errors with nested field errors (ValidationFieldError
)NotNullError
— Violation of a "not null" constraintNotFoundError
— Missing entity- Custom errors via inheritance from
BaseError
Structured Metadata
Each error contains:- Error type (
ErrorType
) — Classification (Validation, NotNull, etc.) - Technical details in
Metadata
:- Error code (
ErrorCode
) - Field/entity name
- Invalid value
- Documentation reference
- Additional parameters (see
ErrorMetadataType
)
- Error code (
- Error type (
Error Hierarchy
- Base class
BaseError
implements FluentResults'IError
- Support for nested errors via the
Reasons
collection
- Base class
Usage Example
// Object validation
var errors = new List<ValidationFieldError>
{
new ValidationFieldError(
message: "Invalid email format",
errorCode: "INVALID_EMAIL",
fieldName: "Email",
attemptedValue: "user@"
),
new NotNullError("Username")
};
var validationResult = Result.Fail(new ValidationError("User", errors));
// Error handling
if (validationResult.IsFailed)
{
foreach (var error in validationResult.Errors)
{
if (error is ValidationError ve)
{
Console.WriteLine($"Validation error for {ve.Metadata["EntityType"]}");
foreach (var fieldError in ve.Reasons.Cast<ValidationFieldError>())
{
Console.WriteLine($"{fieldError.Metadata["FieldName"]}: {fieldError.Message}");
}
}
}
}
Integration with FluentResults
- Compatible with all FluentResults features (result chaining, error pipeline handling)
- Errors are automatically serialized into FluentResults' standard structures
Benefits
- Unified error style across application layers
- Prebuilt templates for common scenarios
- Detailed error analysis via structured metadata
- Easy extensibility (create new error types via inheritance)
Extension Guidelines
- Adding Specific Errors
Create error classes by inheriting fromBaseError
:
public sealed class DatabaseError : BaseError
{
// Constructor implementation
public DatabaseError(...) : base(...) { ... }
}
- Error Constructor
When implementing a constructor:
- Pass parameters to the parent class via
base()
- Use the
CreateMetadata()
method to build the metadata dictionary
Required parameters:
string message
— User-friendly error messageErrorType errorType
— Error type from theErrorType
enumeration
Optional parameters:
IEnumerable<IError>? reasons = null
— List of errors that caused the current oneDictionary<string, object>? metadata = null
— Technical details about the error. Can be passed via theCreateMetadata()
method:SomeError( ..., metadata: CreateMetadata( (ErrorMetadataType.FieldName, "SOME_FIELD"), (ErrorMetadataType.ErrorCode, "CUSTOM_CODE") ) )
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- FluentResults (>= 3.16.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.