Lukdrasil.Error
1.0.0
dotnet add package Lukdrasil.Error --version 1.0.0
NuGet\Install-Package Lukdrasil.Error -Version 1.0.0
<PackageReference Include="Lukdrasil.Error" Version="1.0.0" />
<PackageVersion Include="Lukdrasil.Error" Version="1.0.0" />
<PackageReference Include="Lukdrasil.Error" />
paket add Lukdrasil.Error --version 1.0.0
#r "nuget: Lukdrasil.Error, 1.0.0"
#:package Lukdrasil.Error@1.0.0
#addin nuget:?package=Lukdrasil.Error&version=1.0.0
#tool nuget:?package=Lukdrasil.Error&version=1.0.0
Error
Error is an .NET library for structured error and result management. It provides a consistent, extensible, and type-safe way to represent, build, and propagate errors in your applications and APIs.
Table of Contents
Features
- Strongly-typed error representation using C# records and enums
- Fluent ErrorBuilder for easy and safe error construction
- Integration with ASP.NET Core via
ProblemDetails - Support for error severity levels (
Error,Warning,Info) - Format string validation with runtime safety and caller info in exceptions
- Unit tested and .NET 8 ready
Installation
Add a reference to the Lukdrasil.Error project or package in your solution:
If using as a project reference
<PackageReference Include="Lukdrasil.Error" Version="x.y.z" />
Or clone the repository and add the project to your solution.
Usage
Basic Error Creation
using Lukdrasil.Error;
var error = new Error("ERR001", ErrorSeverity.Error, "Something went wrong");
var problemDetails = error.ToProblemDetails();
Error with Formatting
using Lukdrasil.Error;
var error = new Error(
"ERR_FORMAT",
ErrorSeverity.Warning,
string.Format("Invalid value for field '{0}' at line '{1}'", "Name", 42)
);
Using ErrorBuilder (Fluent API)
using Lukdrasil.Error;
var error = new ErrorBuilder()
.WithCode("ERR_USER")
.WithSeverity(ErrorSeverity.Error)
.WithDescription("User with id {0} not found", userId)
.Build();
Using ErrorBuilder with Direct Text
using Lukdrasil.Error;
var error = new ErrorBuilder()
.WithCode("ERR_CUSTOM")
.WithDescriptionText("A custom error occurred.")
.Build();
Exception Safety
If you use a format string with placeholders but do not provide arguments, the builder will throw an ArgumentException with caller info:
using Lukdrasil.Error;
var error = new ErrorBuilder()
.WithDescription("Field {0} is required");
error.Build(); // Throws ArgumentException with caller info
Project Structure
Error- Main error record with code, severity, and descriptionErrorBuilder- Fluent builder for safe error creationBaseError- Abstract base for custom error typesErrorSeverity- Enum for error levels- Unit tests in
Error.Tests
Contributing
Contributions are welcome! Please open issues or submit pull requests for any features, bugfixes, or improvements.
- Fork the repository
- Create your feature branch (
git checkout -b feature/YourFeature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/YourFeature) - Open a pull request
License
This project is licensed under the MIT License. See the LICENSE file for details.
| 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. |
-
net9.0
- No dependencies.
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 |
|---|