Baubit.Traceability
2025.48.1
dotnet add package Baubit.Traceability --version 2025.48.1
NuGet\Install-Package Baubit.Traceability -Version 2025.48.1
<PackageReference Include="Baubit.Traceability" Version="2025.48.1" />
<PackageVersion Include="Baubit.Traceability" Version="2025.48.1" />
<PackageReference Include="Baubit.Traceability" />
paket add Baubit.Traceability --version 2025.48.1
#r "nuget: Baubit.Traceability, 2025.48.1"
#:package Baubit.Traceability@2025.48.1
#addin nuget:?package=Baubit.Traceability&version=2025.48.1
#tool nuget:?package=Baubit.Traceability&version=2025.48.1
Baubit.Traceability
A lightweight .NET library for building robust error handling and result tracing in .NET applications using the FluentResults pattern.
Overview
Baubit.Traceability provides a comprehensive set of abstractions and extension methods for working with operation results, errors, and success states. It extends the popular FluentResults library with additional traceability features, making it easier to track, understand, and debug complex operation chains in your applications.
Features
- 🎯 Abstract Base Classes - Ready-to-use base classes for errors, reasons, and successes
- 🔍 Rich Traceability - Track operation results with metadata and timestamps
- 🛡️ Type-Safe Error Handling - Leverage .NET type system for robust error handling
- 🔄 FluentResults Integration - Seamlessly extends FluentResults with additional functionality
- 📦 Zero Configuration - Works out of the box with sensible defaults
Installation
dotnet add package Baubit.Traceability
Quick Start
Basic Error Handling
using Baubit.Traceability;
using FluentResults;
public class UserService
{
public Result<User> GetUser(int id)
{
var result = ValidateUserId(id);
if (result.IsFailed)
{
return result.ToResult<User>()
.AddReasonIfFailed(new UserNotFoundReason(id));
}
var user = FetchUserFromDatabase(id);
return Result.Ok(user);
}
}
Custom Errors and Reasons
using Baubit.Traceability.Errors;
using Baubit.Traceability.Reasons;
public class UserNotFoundError : AError
{
public UserNotFoundError(int userId)
: base([], $"User with ID {userId} was not found", new Dictionary<string, object>
{
{ "UserId", userId },
{ "Timestamp", DateTime.UtcNow }
})
{
}
}
public class UserNotFoundReason : AReason
{
public UserNotFoundReason(int userId)
: base($"User {userId} does not exist in the database", new Dictionary<string, object>
{
{ "UserId", userId }
})
{
}
}
Using Extension Methods
using Baubit.Traceability;
using FluentResults;
// Throw exception on failure
var result = PerformOperation()
.ThrowIfFailed();
// Add success markers
var successResult = Result.Ok(data)
.AddSuccessIfPassed(new OperationSuccess("Data loaded successfully"));
// Unwrap nested reasons
var reasons = complexResult.UnwrapReasons();
// Dispose resources safely
var disposables = new List<IDisposable> { resource1, resource2 };
var disposeResult = disposables.Dispose();
Working with Successes
using Baubit.Traceability.Successes;
public class DataSavedSuccess : ASuccess
{
public DataSavedSuccess(string entityId)
: base($"Data saved successfully for entity {entityId}", new Dictionary<string, object>
{
{ "EntityId", entityId },
{ "SavedAt", DateTime.UtcNow }
})
{
}
}
public Result SaveData(Data data)
{
// Save logic...
return Result.Ok()
.AddSuccessIfPassed(new DataSavedSuccess(data.Id));
}
API Reference
Base Classes
AError
Abstract base class for custom error types. Provides:
Message- Error messageReasons- List of nested error reasonsMetadata- Additional context as key-value pairsCreationTime- Timestamp when error was created
AReason
Abstract base class for custom reason types. Provides:
Message- Reason descriptionMetadata- Additional context as key-value pairsCreationTime- Timestamp when reason was created
ASuccess
Abstract base class for custom success types. Inherits from AReason and implements ISuccess.
Extension Methods
Result Extensions
ThrowIfFailed<TResult>()- ThrowsFailedOperationExceptionif result is failedThrowIfFailed<TResult>(Task<TResult>)- Async version of ThrowIfFailedAddSuccessIfPassed<TResult>(params ISuccess[])- Adds success markers when result succeedsAddReasonIfFailed(params IReason[])- Adds reasons when result failsAddErrorIfFailed<TError>(params TError[])- Adds errors when result failsUnwrapReasons<TResult>()- Recursively unwraps all reasons including nested exceptionsGetNonErrors<TResult>()- Returns only non-error reasons
Collection Extensions
Dispose<TDisposable>(IList<TDisposable>)- Safely disposes a collection of disposable objects
Exceptions
FailedOperationException
Exception thrown by ThrowIfFailed() when a result has failed. Contains the original IResultBase result.
Advanced Scenarios
Nested Error Unwrapping
try
{
var result = PerformComplexOperation()
.ThrowIfFailed();
}
catch (FailedOperationException ex)
{
var allReasons = ex.Result.UnwrapReasons();
// Process all reasons including those from nested exceptions
}
Conditional Success Tracking
var result = Result.Ok(data);
if (shouldLogSuccess)
{
result = result.AddSuccessIfPassed(
(r, successes) => r.WithSuccesses(successes),
new OperationSuccess("Operation completed")
);
}
Resource Cleanup
var resources = new List<IDisposable>
{
connection,
transaction,
reader
};
var cleanupResult = resources.Dispose();
if (cleanupResult.IsFailed)
{
logger.LogError("Failed to dispose resources", cleanupResult.Errors);
}
Building from Source
# Clone the repository
git clone https://github.com/pnagoorkar/Baubit.Traceability.git
cd Baubit.Traceability
# Build the solution
dotnet build
# Run tests
dotnet test
# Run tests with coverage
dotnet test --collect:"XPlat Code Coverage"
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Guidelines
- Ensure all tests pass before submitting PR
- Add tests for new functionality
- Maintain 100% code coverage
- Follow existing code style and conventions
- Update documentation for API changes
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
This library is part of the Baubit framework ecosystem and was extracted to provide standalone traceability functionality.
Support
Copyright © 2025 Prashant Nagoorkar
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- FluentResults (>= 3.16.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Baubit.Traceability:
| Package | Downloads |
|---|---|
|
Baubit.Reflection
A utility library for providing enhanced reflection capabilities with functional error handling. Features include safe type resolution, version-aware assembly name comparison, simplified assembly-qualified name formatting, and embedded resource reading using FluentResults for robust error handling. |
|
|
Baubit.Validation
A lightweight validation framework for .NET that provides a generic IValidator interface with FluentResults integration for clean validation patterns. |
|
|
Baubit.Tasks
Task utilities featuring TimedCancellationTokenSource for automatic timeout-based cancellation and Task extension methods with FluentResults integration for improved error handling and cancellation token management. |
GitHub repositories
This package is not used by any popular GitHub repositories.