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" />
                    
Directory.Packages.props
<PackageReference Include="PlopyBlopy.FluentResults.Errors" />
                    
Project file
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
                    
#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
                    
Install PlopyBlopy.FluentResults.Errors as a Cake Addin
#tool nuget:?package=PlopyBlopy.FluentResults.Errors&version=1.0.7
                    
Install PlopyBlopy.FluentResults.Errors as a Cake Tool

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

  1. 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" constraint
    • NotFoundError — Missing entity
    • Custom errors via inheritance from BaseError
  2. 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)
  3. Error Hierarchy

    • Base class BaseError implements FluentResults' IError
    • Support for nested errors via the Reasons collection

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

  1. Adding Specific Errors
    Create error classes by inheriting from BaseError:
public sealed class DatabaseError : BaseError 
{ 
    // Constructor implementation
    public DatabaseError(...) : base(...) { ... } 
}
  1. 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 message
  • ErrorType errorType — Error type from the ErrorType enumeration

Optional parameters:

  • IEnumerable<IError>? reasons = null — List of errors that caused the current one
  • Dictionary<string, object>? metadata = null — Technical details about the error. Can be passed via the CreateMetadata() method:
    SomeError(
        ...,
        metadata: CreateMetadata(
            (ErrorMetadataType.FieldName, "SOME_FIELD"),
            (ErrorMetadataType.ErrorCode, "CUSTOM_CODE")
        )
    )
    
Product 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.7 109 5/23/2025
1.0.6 289 5/5/2025