Scaffolds a Result/Error pattern (errors as values) across C#, TypeScript, Python, Java/Kotlin, Go, and Rust. Generates types, helpers, and HTTP error mapping for railway-oriented programming.
Ships in AI for Developers Toolkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Introduce errors-as-values so expected failures (validation, not-found, conflict, forbidden) are returned, not thrown - and map them to HTTP responses in exactly one place at the edge.
Works on a target: a file, folder, project/repo, or GitHub URL (git clone --depth 1 <url>). If a Result/Either type or error convention already exists, extend it instead of adding a second one.
| Manifest | Stack | Look for | Default |
|---|---|---|---|
*.csproj | C# / .NET | OneOf, ErrorOr, FluentResults, Result<, throw new .*Exception | Small in-house Result<T> + Error, or the library already referenced |
package.json | TypeScript | neverthrow, Result<, { ok: true, throw new | Discriminated union Result<T, E> (or neverthrow if present) |
pyproject.toml / requirements*.txt | Python | returns, Ok(/Err(, raise .*Error | Frozen Ok/Err dataclasses + match; or domain exceptions mapped centrally if that's the house style |
pom.xml / build.gradle(.kts) | Java / Kotlin | Either, sealed interface, kotlin.Result, Arrow | Java: sealed interface + records; Kotlin: sealed class or Arrow Either |
go.mod | Go | errors.Is, errors.As, var Err | No Result type - (T, error) with sentinel/typed domain errors |
Cargo.toml | Rust | thiserror, Result< | Native Result<T, E> + a domain error enum |
Grep for the throw sites that represent expected outcomes (validation, not found, conflict) - those are the conversion candidates.
validation, not_found, conflict, forbidden, unexpected) with a stable code and message. Kinds drive HTTP mapping; codes are for clients.writeError helper), returning Problem Details (RFC 9457 / 7807) consistently.map/bind (or early returns) so callers don't nest if chains.OneOf, neverthrow, Arrow, or typed errors already exist, extend them.(T, error)).public readonly record struct Error(string Code, string Message, ErrorKind Kind)
{
public static readonly Error None = new(string.Empty, string.Empty, ErrorKind.None);
public static Error NotFound(string msg) => new("not_found", msg, ErrorKind.NotFound);
public static Error Validation(string msg) => new("validation", msg, ErrorKind.Validation);
public static Error Conflict(string msg) => new("conflict", msg, ErrorKind.Conflict);
}
public readonly struct Result<T>
{
public bool IsSuccess { get; }
public T? Value { get; }
public Error Error { get; }
private Result(T v){ IsSuccess = true; Value = v; Error = Error.None; }
private Result(Error e){ IsSuccess = false; Value = default; Error = e; }
public static Result<T> Success(T v) => new(v);
public static Result<T> Failure(Error e) => new(e);
public static implicit operator Result<T>(T v) => Success(v);
public static implicit operator Result<T>(Error e) => Failure(e);
}
Handler:
public async Task<Result<OrderDto>> Handle(GetOrder q, CancellationToken ct)
{
var order = await _db.Orders.AsNoTracking().FirstOrDefaultAsync(o => o.Id == q.Id, ct);
if (order is null) return Error.NotFound($"Order {q.Id} not found");
return _mapper.ToDto(order);
}
Mapping to HTTP (one place):
public static IResult ToHttp<T>(this Result<T> r) => r.IsSuccess
? TypedResults.Ok(r.Value)
: r.Error.Kind switch
{
ErrorKind.NotFound => TypedResults.Problem(r.Error.Message, statusCode: 404),
ErrorKind.Validation => TypedResults.Problem(r.Error.Message, statusCode: 400),
ErrorKind.Conflict => TypedResults.Problem(r.Error.Message, statusCode: 409),
_ => TypedResults.Problem(r.Error.Message)
};
If the codebase already uses OneOf<T, Error>, ErrorOr, or FluentResults, extend that rather than introducing a competing type.
export type Result<T, E = AppError> = { ok: true; value: T } | { ok: false; error: E };
export const ok = <T>(value: T): Result<T, never> => ({ ok: true, value });
export const err = <E>(error: E): Result<never, E> => ({ ok: false, error });
export type AppError =
| { kind: "validation"; message: string; fields?: Record<string, string> }
| { kind: "not_found"; message: string }
| { kind: "conflict"; message: string };
const STATUS: Record<AppError["kind"], number> = { validation: 400, not_found: 404, conflict: 409 };
// one place: route helper / error-mapping middleware
export function send<T>(res: Response, r: Result<T>, okStatus = 200) {
if (r.ok) return res.status(okStatus).json(r.value);
return res.status(STATUS[r.error.kind])
.type("application/problem+json")
.json({ title: r.error.kind, detail: r.error.message, status: STATUS[r.error.kind] });
}
The union forces callers to check r.ok. If neverthrow is installed, use its Result/ResultAsync and match instead. NestJS: map in one exception filter or interceptor.
@dataclass(frozen=True)
class Ok(Generic[T]):
value: T
@dataclass(frozen=True)
class Err:
kind: Literal["validation", "not_found", "conflict"]
message: str
Result = Ok[T] | Err
async def get_order(order_id: UUID) -> Result[OrderDto]:
order = await repo.get(order_id)
if order is None:
return Err("not_found", f"Order {order_id} not found")
return Ok(OrderDto.from_domain(order))
STATUS = {"validation": 400, "not_found": 404, "conflict": 409}
def to_response(r: Result[Any], ok_status: int = 200) -> JSONResponse: # one place
match r:
case Ok(value):
return JSONResponse(jsonable_encoder(value), status_code=ok_status)
case Err(kind, message):
return JSONResponse({"title": kind, "detail": message, "status": STATUS[kind]},
status_code=STATUS[kind], media_type="application/problem+json")
Python culture leans on exceptions; if the codebase does too, the equivalent "one place" pattern is a small domain exception hierarchy plus a single app.exception_handler(DomainError) (FastAPI) or DRF EXCEPTION_HANDLER. Say which you chose and why. Use the returns library only if it's already in use.
public sealed interface Result<T> permits Result.Ok, Result.Err {
record Ok<T>(T value) implements Result<T> {}
record Err<T>(AppError error) implements Result<T> {}
}
public record AppError(Kind kind, String message) { public enum Kind { VALIDATION, NOT_FOUND, CONFLICT } }
// one place: a small mapper used by controllers
static <T> ResponseEntity<?> toResponse(Result<T> r) {
return switch (r) {
case Result.Ok<T> ok -> ResponseEntity.ok(ok.value());
case Result.Err<T> e -> {
var status = switch (e.error().kind()) {
case VALIDATION -> HttpStatus.BAD_REQUEST;
case NOT_FOUND -> HttpStatus.NOT_FOUND;
case CONFLICT -> HttpStatus.CONFLICT;
};
yield ResponseEntity.of(ProblemDetail.forStatusAndDetail(status, e.error().message())).build();
}
};
}
Needs Java 21 pattern matching for switch. If Vavr is in use, Either<AppError, T> is the equivalent. Kotlin: a sealed class result or Arrow's Either with fold; kotlin.Result only wraps Throwable, so it's a poor fit for domain errors. Teams that prefer exceptions: domain exceptions + one @RestControllerAdvice returning ProblemDetail.
Go already has errors as values - don't introduce a generic Result type. Make the errors typed and map them once:
var (
ErrNotFound = errors.New("not found")
ErrConflict = errors.New("conflict")
)
type ValidationError struct{ Field, Msg string }
func (e *ValidationError) Error() string { return e.Field + ": " + e.Msg }
func (s *Service) GetOrder(ctx context.Context, id string) (OrderDTO, error) {
o, err := s.repo.Get(ctx, id)
if errors.Is(err, sql.ErrNoRows) { return OrderDTO{}, fmt.Errorf("order %s: %w", id, ErrNotFound) }
if err != nil { return OrderDTO{}, err } // infrastructure error, passes through
return toDTO(o), nil
}
func writeError(w http.ResponseWriter, err error) { // one place
var ve *ValidationError
switch {
case errors.As(err, &ve): writeProblem(w, http.StatusBadRequest, ve.Error())
case errors.Is(err, ErrNotFound): writeProblem(w, http.StatusNotFound, err.Error())
case errors.Is(err, ErrConflict): writeProblem(w, http.StatusConflict, err.Error())
default: writeProblem(w, http.StatusInternalServerError, "internal error") // log err
}
}
Native Result<T, E> with a domain error enum (thiserror) and one IntoResponse impl (axum) or ResponseError impl (actix-web) for the HTTP mapping.
## Detected
<stack, existing convention found, choice made and why>
## Files
<the Result/Error type (or error set), helpers, the single HTTP mapping>
## Conversions
| Location | Before (throw/raise/panic) | After |
## Left as exceptions
<what intentionally stays an exception and why>
"Add a Result pattern to this project", "stop throwing for validation in these handlers", "map domain errors to HTTP in one place", "Result type for my TypeScript services", "errors as values in my FastAPI app", "sealed Result type for Java 21", "clean up error handling in my Go handlers with errors.Is". Pairs with cqrs-setup (handler return types), api-endpoint-scaffolder (edge mapping), and the code-reviewer agent.
What SKILL.md sets; muted values are Claude Code's defaults
45 skills in this plugin
/api-endpoint-scaffolderScaffold HTTP API endpoints in any stack - ASP.NET Core Minimal APIs or controllers, Express, Fastify, NestJS, FastAPI, Django REST Framework, Spring Boot controllers, Go net/http, chi, Gin - one feature per endpoint (REPR style) with request validation, typed responses, route grouping, auth, and OpenAPI metadata. Use this skill whenever the user wants to add an endpoint or route, convert controllers to minimal APIs, structure routes or routers, set up endpoint groups, TypedResults, route handlers, request DTOs/schemas (zod, Pydantic, Bean Validation, binding tags), or asks "how do I add an endpoint / structure my API routes". Always use this skill for endpoint scaffolding; it generates a complete, validated endpoint that matches the project's conventions./architecture-test-generatorGenerate architecture tests / fitness functions that fail the build when architectural rules are violated - layer dependencies, module boundaries, cycles, naming, and visibility conventions - in any stack: NetArchTest or ArchUnitNET (.NET), ArchUnit or Konsist (Java/Kotlin), dependency-cruiser or eslint-plugin-boundaries (TypeScript/JavaScript), import-linter (Python), go-arch-lint or depguard (Go). Use this skill whenever the user wants architecture tests, to enforce layering or the dependency rule, dependency rules as tests, import rules, forbidden imports, no circular dependencies, naming conventions, fitness functions, or asks "how do I stop people breaking the architecture / enforce my layers / keep modules from importing each other". Always use this skill for architecture-test requests; it generates rules matching the project's real structure./ai-dev-toolkit:result-pattern-scaffolderfrom AI for Developers Toolkit
npx claudepluginhub stefanthecode/ai-for-developers --plugin ai-dev-toolkitOther plugins' skills for the same job