kensaurus/cursor-kenji/backend-error-handling
Claude Code and agent skill by kensaurus/cursor-kenji
- community
Checking that the SKILL.md file is still in the repository.
Implement error-handling patterns: boundaries, toasts, one API error shape. Use when "error boundary", "error toast", or "standardize API errors". Plan-only audit → plan-error-handling. Sentry triage → debug-sentry-monitor.
Install
npx vskill@latest install kensaurus/cursor-kenji/backend-error-handlingSKILL.md
Error Handling Skill
Degree of freedom: MIXED. Which layer and message [HIGH freedom]; existing-type/boundary probes [LOW freedom — run exactly].
This skill vs neighbors
| Skill | Owns | |
|---|---|---|
| backend-error-handling (this) | Implement error boundaries, toasts, and one API error shape | |
plan-error-handling | Plan-only audit of silent failures and observability gaps | |
debug-sentry-monitor | Operate Sentry: triage and fix issues, cut noise, monitor after deploy |
How to reason
- Observe — existing error types, boundaries,
ActionResult/ApiError - Interpret — missing layer vs inconsistent shape vs swallowed catch
- Classify — reuse-existing / extend-codes / add-boundary / toast-only
- Severity — unhandled 500 on a mutation outranks a missing toast
Worked example
Observe:createUserthrows PrismaP2002; UI shows a blank catch;ActionResultalready lives intypes/errors.ts.Interpret: known conflict is unmapped; no field/toast path.Classify: reuseActionResult+CONFLICT; toast the message; do not add a second error type.Verify: duplicate email returns{ success: false, error: { code: 'CONFLICT' } }; form alert shown.
Self-critique before reporting
- Reuse shape — searched
ActionResult/ApiError/error.tsxbefore adding a type - User-safe —
INTERNAL_ERRORis generic; PII is not in the client message - Layered — boundary + action result + toast, not toast-only
- Right owner — plan-only observability audit →
plan-error-handling; live Sentry triage →debug-sentry-monitor
Layered error handling for full-stack apps: one action-result shape, boundaries, and toasts.
When to Use
- Adding error handling to new features
- Improving error user experience
- Standardizing error responses
- Debugging error propagation
- Adding error monitoring
Check existing first [LOW freedom — run exactly]
Before adding ANY error handling, verify:
- Check for existing error types:
- Check for existing error boundaries:
- Check for existing error utilities:
- Check established error response patterns:
Why: Inconsistent error handling confuses users and complicates debugging. Always follow established patterns.
Error Handling Layers [HIGH freedom]
- UI layer — error boundaries, form validation errors, toast notifications.
- Application layer — Server Action errors, API route errors, business-logic errors.
- Data layer — database errors, Zod validation errors, external API errors.
- Every error is caught at the lowest layer that can name it and surfaces upward as
ActionResultor a typed API error, never as a raw throw to the UI.
Layer diagram: references/server-patterns.md §Error handling layers.
Standard Error Types [HIGH freedom]
- One
AppError { code, message, details? };codeis machine-readable,messageis user-safe. ActionResult<T>is a discriminated union onsuccess; never return{ data, error }both-optional.- Error codes:
VALIDATION_ERROR,NOT_FOUND,UNAUTHORIZED,FORBIDDEN,CONFLICT,RATE_LIMITED,INTERNAL_ERROR.
Full ErrorCode constant: references/server-patterns.md §Standard error types.
Server Action Error Handling [HIGH freedom]
safeParsetheFormData; returnVALIDATION_ERRORwithflatten().fieldErrorsasdetails.- Check the session; return
UNAUTHORIZEDwith a "please sign in" message. - Run the mutation,
revalidatePath, return{ success: true, data }. - Map known errors (Prisma
P2002→CONFLICTwith a specific message). - Log unknown errors server-side; return a generic
INTERNAL_ERRORmessage, never the stack.
Full createUser action: references/server-patterns.md §Server Action error handling.
Form Error Display (React 19+) [HIGH freedom]
useActionState(createUser, null)for state;useFormStatusin a childSubmitButtonfor pending.- Field errors come from
state.error.details; render inline witharia-invalidandaria-describedby. - Non-validation errors render once in a
role="alert"banner above the fields. useOptimisticfor optimistic UI updates.
Full UserForm component: references/ui-patterns.md §Form error display.
React Error Boundaries [HIGH freedom]
app/error.tsxper page segment:'use client', receives{ error, reset }, logs inuseEffect, shows a "Try again" button.app/global-error.tsxfor the root: must render its own<html>and<body>.- Boundaries catch render errors only; async and event errors go through
ActionResultor TanStack Query.
Both boundaries in full: references/ui-patterns.md §React error boundaries.
API Route Error Handling [HIGH freedom]
- Same
{ error: { code, message, details? } }body shape for every non-2xx response. 400forVALIDATION_ERRORandINVALID_JSON(SyntaxErrorfromrequest.json()),201on create,500generic.- Log the route name with the error; never return stack traces.
Full POST /api/products handler: references/server-patterns.md §API route error handling.
TanStack Query Error Handling [HIGH freedom]
- In
queryFn/mutationFn, thrownew Error(body.error?.message ?? fallback)when!res.okso the UI gets the server message. retry: no retry on 401/403; up to 3 attempts otherwise.- Mutations:
onSuccessinvalidates the query key andtoast.success;onError→toast.error(error.message).
useProducts and useCreateProduct hooks: references/ui-patterns.md §TanStack Query error handling.
Error State UI Components [HIGH freedom]
- One reusable
ErrorState({ title, message, onRetry? }): icon, heading, message, optional retry button. - Use it for query errors (
error+refetch) instead of ad-hoc red text per list.
Full ErrorState component: references/ui-patterns.md §Error state UI components.
Further reading
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/backend-error-handling/SKILL.md
Popularity
- Repository stars
- 9
- 7-day trend score
- 12
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
[](https://verified-skill.com/skills/kensaurus/cursor-kenji/backend-error-handling)