ApricotFramework.ErrorDefinitions 0.1.0

Prefix Reserved
dotnet add package ApricotFramework.ErrorDefinitions --version 0.1.0
                    
NuGet\Install-Package ApricotFramework.ErrorDefinitions -Version 0.1.0
                    
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="ApricotFramework.ErrorDefinitions" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ApricotFramework.ErrorDefinitions" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="ApricotFramework.ErrorDefinitions" />
                    
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 ApricotFramework.ErrorDefinitions --version 0.1.0
                    
#r "nuget: ApricotFramework.ErrorDefinitions, 0.1.0"
                    
#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.
#:package ApricotFramework.ErrorDefinitions@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ApricotFramework.ErrorDefinitions&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=ApricotFramework.ErrorDefinitions&version=0.1.0
                    
Install as a Cake Tool

ApricotFramework.ErrorDefinitions

NuGet NuGet CI License

One error contract for a fleet of services: throw a classified error anywhere, and every service and client reads the same RFC 9457 problem document back — including when the peer is not one of yours.

ApricotFramework.ErrorDefinitions is the zero-dependency core.

Install

dotnet add package ApricotFramework.ErrorDefinitions
dotnet add package ApricotFramework.ErrorDefinitions.AspNetCore

Usage

using ApricotFramework.ErrorDefinitions.AspNetCore.Extensions;

builder.Services.AddErrorDefinitions();      // nothing to configure
app.UseExceptionHandler();
// Throwing: the kind decides the status, the code decides the text a client shows.
var author = Ensure.Found(await repository.Get(id), ContentErrors.AuthorNotFound);

throw Err.Validation(ContentErrors.InvalidLocale, payload: new Dictionary<string, object?>
{
    ["locale"] = locale,          // the client renders its own message from the code and these
}).AsException();

// Reporting several at once, so a caller fixing a form submits it once.
new ErrorCollector()
    .AddIf(string.IsNullOrWhiteSpace(input.Name), Err.Validation(ContentErrors.InvalidName))
    .AddIf(!input.Email.Contains('@'), Err.Validation(ContentErrors.InvalidEmail))
    .ThrowIfAny();
// What the caller receives — application/problem+json
{
  "type": "about:blank",
  "title": "Validation failed",
  "status": 400,
  "detail": "That locale is not published.",
  "instance": "/api/content",
  "errors": [
    { "kind": "validation", "code": "CONTENT_INVALID_LOCALE",
      "message": "That locale is not published.", "payload": { "locale": "fr" } }
  ]
}
// Reading another service's failure, from the zero-dependency core.
using var response = await client.GetAsync(uri, cancellationToken);

await response.EnsureNoErrorsAsync(cancellationToken);   // rethrows the peer's kind and code as your own

An unmapped exception never reaches the caller: it is reported as internal with no message, no exception type and no stack trace, because that text routinely holds connection strings and SQL. The exception goes to the log at error level instead, and that log is the only record of it — the framework's own middleware does not log an exception once a handler has answered it.

The sixteen kinds are google.rpc.Code under names that read better over HTTP, so the same classification maps to gRPC without a second table. schemas/ publishes the whole contract as JSON for clients that are not .NET.

Full documentation: https://projectapricot.dev

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.
  • net10.0

    • No dependencies.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on ApricotFramework.ErrorDefinitions:

Package Downloads
ApricotFramework.ErrorDefinitions.AspNetCore

ASP.NET Core integration for ApricotFramework.ErrorDefinitions: an exception handler that turns classified errors into RFC 9457 problem+json responses, an additive registry so a library can map its own exception types without writing a handler, and startup validation of the options.

ApricotFramework.Grpc.ErrorDefinitions

The gRPC wire contract for ApricotFramework error definitions: classified errors travel in google.rpc.Status details with their payloads intact, translated in both directions, and a client interceptor rethrows a failed call as the exception the server threw.

ApricotFramework.Grpc.Server

Answers a failed gRPC call with classified errors, asking the same exception mappers that already answer this service's HTTP requests, so a failure means the same thing whichever way a caller reached it.

ApricotFramework.Grpc.Client

How this service's gRPC clients behave: one place to reach them from, a default deadline for calls that set none, and the transport strictness a deployment asks for. Discovery, credentials and error translation are added on top of it, separately.

ApricotFramework.Grpc.Client.Authentication

Presents this service's own access token on outbound gRPC calls, obtained through ApricotFramework.Authentication, and reports a failure to obtain one as a fault of this service rather than of whoever called it.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 294 8/15/2026