senrecep/csharpessentials/csharpessentials-errors

Claude Code and agent skill by senrecep/csharpessentials

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when creating structured error values. Covers Error factory methods (Failure/Validation/NotFound/Conflict/Unauthorized/Forbidden/Unexpected), ErrorMetadata for contextual data, HTTP status mapping, and domain-specific static error class hierarchies.

Install

npx vskill@latest install senrecep/csharpessentials/csharpessentials-errors

SKILL.md

CSharpEssentials.Errors

Errors are values, not exceptions. Error is a readonly record struct with a code, description, type, and optional metadata.

Installation

bash
dotnet add package CSharpEssentials.Errors

Namespace

csharp
using CSharpEssentials.Errors;

Creating Errors

csharp
// ErrorType: Failure | Unexpected | Validation | Conflict | NotFound | Unauthorized | Forbidden | Unknown (no factory)
Error failure = Error.Failure("order.failed", "Order could not be processed.");
Error validation = Error.Validation("email.invalid", "Email format is invalid.");
Error notFound = Error.NotFound("user.not_found", "User not found.");
Error conflict = Error.Conflict("email.taken", "Email is already registered.");
Error unauthorized = Error.Unauthorized("token.expired", "Token has expired.");
Error forbidden = Error.Forbidden("access.denied", "Insufficient permissions.");
Error unexpected = Error.Unexpected("sys.error", "An unexpected error occurred.");
Error fromEx = Error.Exception(ex); // code = exception type name, description = message, metadata = exception details

Error Properties

csharp
string code = error.Code; // "email.invalid"
string description = error.Description; // "Email format is invalid." (there is no .Message)
ErrorType type = error.Type; // ErrorType.Validation
int numeric = error.NumericType; // int value of Type
ErrorMetadata? meta = error.Metadata; // nullable

Every factory has defaults for code and description (Error.NotFound() has the code NotFound). Two errors are equal when type, code, description and metadata entries are equal.

ErrorMetadata

csharp
Error withMeta = Error.NotFound(
"User.NotFound",
"User was not found.",
new ErrorMetadata()
.AddMetadata("TraceId", traceId)
.AddMetadata("RequestPath", "/api/users/1"));
// .AddMetadata(): NOT .WithMetadata(); an existing key is kept, not overwritten

Combining Errors

csharp
Error[] merged = error1 + error2; // operator +
Error[] many = Error.CreateMany(error1, error2, error3);

HTTP Status Mapping

csharp
int status = ErrorType.NotFound.ToHttpStatusCode(); // 404
int status2 = ErrorType.Validation.ToHttpStatusCode(); // 400 (Failure/Unexpected/Unknown map to 500)
ErrorType et = 401.ToErrorType(); // Unauthorized

Validation 400, Unauthorized 401, Forbidden 403, NotFound 404, Conflict 409. ToErrorType reverses 400, 401, 403, 404, 409 and 500 (Failure); any other status gives Unexpected.

Domain-Specific Error Hierarchies

Error is a readonly record struct, so it cannot be subclassed. Use static classes per aggregate:

csharp
public static class UserErrors
{
public static Error NotFound(Guid id) =>
Error.NotFound("User.NotFound", $"User '{id}' was not found.");
public static readonly Error AlreadyExists =
Error.Conflict("User.AlreadyExists", "A user with that email already exists.");
public static Error InvalidAge(int age) =>
Error.Validation("User.InvalidAge", $"Age {age} is invalid; must be 18 or older.");
public static readonly Error Unauthorized =
Error.Unauthorized("User.Unauthorized", "You are not authorized to perform this action.");
}
public static class OrderErrors
{
public static readonly Error EmptyCart =
Error.Validation("Order.EmptyCart", "Cannot place an order with an empty cart.");
public static Error InsufficientFunds(decimal required, decimal available) =>
Error.Failure(
"Order.InsufficientFunds",
$"Payment requires {required:C} but only {available:C} available.",
new ErrorMetadata()
.AddMetadata("Required", required)
.AddMetadata("Available", available));
}
// Usage: implicit Error → Result<T>
public Result<User> FindUser(Guid id)
{
User? user = _repo.Find(id);
return user is null ? UserErrors.NotFound(id) : user;
}

Domain Exceptions

csharp
using CSharpEssentials.Exceptions;
throw new DomainException(Error.Validation("Order.Invalid", "Total must be greater than zero.")); // .Error holds the Error
throw new EnhancedValidationException(new[] { emailError, passwordError }); // .Errors holds the Error[]

Best Practices

  • Group errors in static classes per aggregate for IDE autocomplete + type-safe codes
  • Use error.Description; the field is named Description, not Message
  • ErrorMetadata uses .AddMetadata(); there is no .WithMetadata()
  • Prefer factory methods (parameterized) over static readonly fields when the message includes runtime data
  • Error is a value type, safe to use as dictionary key, in switch expressions, etc.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
27
Repository forks
1
7-day trend score
0

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/senrecep/csharpessentials/csharpessentials-errors/badge)](https://verified-skill.com/skills/senrecep/csharpessentials/csharpessentials-errors)

Something wrong with this skill or its page? Tell us.