Kodster.Results
0.1.0
dotnet add package Kodster.Results --version 0.1.0
NuGet\Install-Package Kodster.Results -Version 0.1.0
<PackageReference Include="Kodster.Results" Version="0.1.0" />
<PackageVersion Include="Kodster.Results" Version="0.1.0" />
<PackageReference Include="Kodster.Results" />
paket add Kodster.Results --version 0.1.0
#r "nuget: Kodster.Results, 0.1.0"
#:package Kodster.Results@0.1.0
#addin nuget:?package=Kodster.Results&version=0.1.0
#tool nuget:?package=Kodster.Results&version=0.1.0
Kodster.Results
A result type for expected failures, so they travel as return values instead of exceptions.
No dependencies. Safe to reference from a domain or core project without dragging in a DI container, a validation library, or a web framework.
dotnet add package Kodster.Results
Targets .NET 10.
Result and Result<T>
Result represents an operation that either succeeded or failed with an Error.
Result<T> adds a value on the success side.
Result<User> Find(Guid id)
{
var user = _users.SingleOrDefault(u => u.Id == id);
return user is null
? Error.NotFound("User.NotFound", "User was not found.")
: user;
}
Neither branch needs a wrapper call. Error converts implicitly to Result and Result<T>,
and any TValue converts implicitly to a successful Result<TValue>.
Reading one back:
var result = Find(id);
if (result.IsFailure)
{
Console.WriteLine(result.Error.Description);
return;
}
Use(result.Value);
Or branch in a single expression with Match:
var message = result.Match(
onSuccess: user => $"Found {user.Nickname}",
onFailure: error => $"Failed: {error.Code}");
Errors
An Error is a record of a code, a human-readable description, and an ErrorType that says
what kind of failure it is.
Error.Conflict("OAuth.AlreadyLinked", "That provider is already linked to this account.")
ErrorType |
Meaning |
|---|---|
Validation |
Input failed a rule |
Unauthorized |
No valid credentials |
PaymentRequired |
Credentials are valid, but the plan or quota does not cover this |
Forbidden |
Authenticated, but not permitted |
NotFound |
No such resource |
Conflict |
Conflicts with current state |
Gone |
Existed once, permanently removed |
PreconditionFailed |
A supplied precondition did not hold |
Failure |
Anything unexpected |
Each has a matching factory taking a code and description. The set covers outcomes application code decides; it deliberately excludes failures that belong to the transport layer.
ErrorType is serialised by ordinal value, so new members are only ever appended. Inserting
one would change the number every later type serialises as.
Error.None is the sentinel carried by successful results. Constructing a success with an
error, or a failure without one, throws.
Validation results
ValidationResult and ValidationResult<T> are failures that carry many errors rather than
one — the natural shape for input validation, where you want every broken rule at once.
Error[] errors = [
Error.Validation("Nickname", "Nickname is required."),
Error.Validation("Age", "Age must be 13 or older.")
];
return ValidationResult<UserResponse>.WithErrors(errors);
Both implement IValidationResult, so a caller can pattern-match to decide whether to report
one error or all of them:
Error[] toReport = result switch
{
IValidationResult validation => validation.Errors,
_ => [result.Error]
};
They are otherwise ordinary failed results, with Error set to a general
Validation.Error.
Companion packages
- Kodster.CQRS — request/handler abstraction returning these result types, with validation and logging decorators.
- Kodster.Results.AspNetCore —
maps a failed
Resultonto an HTTPProblemDetailsresponse.
License
MIT
| Product | Versions 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. |
-
net10.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Kodster.Results:
| Package | Downloads |
|---|---|
|
Kodster.Results.AspNetCore
Maps Kodster.Results failures onto ASP.NET Core ProblemDetails responses. |
|
|
Kodster.CQRS
Minimal request/handler abstraction with validation and logging decorators. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0 | 135 | 8/19/2026 |