ElvenScript.Error
0.0.4-beta
dotnet add package ElvenScript.Error --version 0.0.4-beta
NuGet\Install-Package ElvenScript.Error -Version 0.0.4-beta
<PackageReference Include="ElvenScript.Error" Version="0.0.4-beta" />
<PackageVersion Include="ElvenScript.Error" Version="0.0.4-beta" />
<PackageReference Include="ElvenScript.Error" />
paket add ElvenScript.Error --version 0.0.4-beta
#r "nuget: ElvenScript.Error, 0.0.4-beta"
#:package ElvenScript.Error@0.0.4-beta
#addin nuget:?package=ElvenScript.Error&version=0.0.4-beta&prerelease
#tool nuget:?package=ElvenScript.Error&version=0.0.4-beta&prerelease
ElvenScript.Error
ElvenScript.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 ElvenScript.Error
project or package in your solution:
If using as a project reference
<PackageReference Include="ElvenScript.Error" Version="x.y.z" />
Or clone the repository and add the project to your solution.
Usage
Basic Error Creation
using ElvenScript.Error;
var error = new Error("ERR001", ErrorSeverity.Error, "Something went wrong");
var problemDetails = error.ToProblemDetails();
Error with Formatting
using ElvenScript.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 ElvenScript.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 ElvenScript.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 ElvenScript.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 | net8.0 is compatible. 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. |
-
net8.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 |
---|