resources/boost/skills/exceptions/SKILL.md
Named, meaningful failure states in your domain. Custom exceptions communicate precise failure reasons to callers and optionally carry domain-specific data.
npx skillsauth add codebar-ag/coding-guidelines exceptionsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
InvoiceAlreadyPaidException).RuntimeException.BillingException).app/Exceptions/InvoiceAlreadyPaid, InsufficientFunds, PaymentGatewayUnavailableException: InvoiceAlreadyPaidExceptionstatic for()) to make throw sites readableparent::__construct() inside the constructorpublic readonly propertiesrender() directly on exceptions that always map to the same HTTP responsebootstrap/app.php using withExceptions()try-catch blocks — let exceptions bubble up to the framework handler unless you must react locallydontReportnamespace App\Exceptions;
use App\Models\Invoice;
use RuntimeException;
class InvoiceAlreadyPaidException extends RuntimeException
{
public function __construct(
public readonly Invoice $invoice,
) {
parent::__construct(
"Invoice #{$invoice->id} has already been paid and cannot be modified."
);
}
public static function for(Invoice $invoice): static
{
return new static($invoice);
}
}
// Throwing — from inside an Action
class MarkInvoiceAsPaid
{
public function execute(Invoice $invoice): void
{
if ($invoice->isPaid()) {
throw InvoiceAlreadyPaidException::for($invoice);
}
$invoice->update(['paid_at' => now()]);
}
}
// Registering in bootstrap/app.php
->withExceptions(function (Exceptions $exceptions) {
$exceptions->render(function (InvoiceAlreadyPaidException $e, Request $request) {
return response()->json([
'ok' => false,
'message' => $e->getMessage(),
'code' => 'invoice_already_paid',
], 422);
});
$exceptions->dontReport([
InvoiceAlreadyPaidException::class,
]);
})
// Catch + rethrow with domain context (do not swallow)
try {
$this->gateway->capture($paymentIntentId);
} catch (GatewayException $exception) {
throw PaymentGatewayUnavailableException::forIntent(
paymentIntentId: $paymentIntentId,
previous: $exception,
);
}
// Successful response shape in controller for contrast
return response()->json([
'ok' => true,
'data' => $invoiceResource,
], 200);
dontReport and map to clear client responses.for()) to verify message and attached context properties.new InvoiceAlreadyPaidException($invoice) at every throw siteActions/SKILL.md — the typical place where domain exceptions are thrownPHP/SKILL.md — for error handling philosophy (avoid try-catch, let bubble)Exception suffixpublic readonly properties when neededrender, withExceptions, dontReport)testing
Translation and localization conventions for Laravel. Use when adding user-facing strings, creating translation files, or working with lang/ directory.
tools
Reusable behaviour shared across multiple unrelated classes. Traits provide shared Eloquent scopes, accessors, lifecycle hooks, and small stateless helper methods.
development
Tailwind CSS v4 styling conventions. Use when working with CSS, Tailwind utilities, or customizing the theme in Laravel projects.
development
Orchestration classes that coordinate multiple Actions, external APIs, or domain operations into a cohesive workflow. Services own transaction boundaries and third-party API integrations.