一键导入
debugging
Debug code errors systematically. Use when analyzing error messages, fixing bugs, resolving build/lint errors, or troubleshooting runtime issues.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Debug code errors systematically. Use when analyzing error messages, fixing bugs, resolving build/lint errors, or troubleshooting runtime issues.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Create robust, error-proof Prisma seed scripts with comprehensive error handling and validation.
Create Next.js 16 API Route Handlers. Use when building REST endpoints (GET, POST, PUT, DELETE), implementing CRUD operations, or creating authenticated APIs with Zod validation.
Create React/Next.js 16 components. Use when building pages, client/server components, forms with useActionState, or UI with shadcn/ui. ALWAYS activate with frontend-design together.
Unit tests with Jest + React Testing Library. CRITICAL - Uses Jest (NOT Vitest).
Write integration tests with Jest for API routes and database operations. Use when testing backend logic, API endpoints, or data layer.
Review code for quality, security, performance, and best practices. Use when reviewing changes before commit, auditing code for issues, or suggesting improvements.
| name | debugging |
| description | Debug code errors systematically. Use when analyzing error messages, fixing bugs, resolving build/lint errors, or troubleshooting runtime issues. |
Cause: Accessing property on undefined/null
// Bad
const name = user.profile.name; // user might be undefined
// Fix: Optional chaining
const name = user?.profile?.name;
// Fix: Default value
const name = user?.profile?.name ?? 'Unknown';
// Fix: Early return
if (!user?.profile) return null;
const name = user.profile.name;
Cause: Calling something that isn't a function
// Check 1: Is it imported correctly?
import { myFunction } from './utils'; // Named export?
import myFunction from './utils'; // Default export?
// Check 2: Is it defined?
console.log(typeof myFunction); // Should be 'function'
// Check 3: Is it bound correctly in classes?
class MyClass {
method = () => {}; // Arrow function preserves 'this'
}
Cause: Using variable before declaration or misspelling
// Check 1: Is it imported?
import { useState } from 'react';
// Check 2: Is it in scope?
function outer() {
const x = 1;
function inner() {
console.log(x); // x is in scope
}
}
// Check 3: Typo?
const userNmae = 'John'; // Typo: userNmae vs userName
// Error: await used outside async function
// Fix: Make function async
async function fetchData() {
const data = await fetch('/api/data');
return data.json();
}
// Error: Unhandled promise rejection
// Fix: Add try-catch
async function fetchData() {
try {
const response = await fetch('/api/data');
if (!response.ok) throw new Error('Fetch failed');
return await response.json();
} catch (error) {
console.error('Fetch error:', error);
return null;
}
}
// Error: Hooks can only be called inside function components
// Fix: Move hook to component level
function MyComponent() {
const [state, setState] = useState(0); // Correct
// Wrong: Hook inside callback
const handleClick = () => {
// const [x, setX] = useState(0); // Error!
};
}
// Error: Rendered more hooks than during the previous render
// Fix: Don't conditionally call hooks
function MyComponent({ show }) {
// Wrong
// if (show) {
// const [state, setState] = useState(0);
// }
// Correct
const [state, setState] = useState(0);
if (!show) return null;
}
// Error: "use client" directive required
// Fix: Add directive at top of file
'use client';
import { useState } from 'react';
export function ClientComponent() {
const [count, setCount] = useState(0);
}
// Error: Cannot use hooks in Server Components
// Fix: Move to Client Component or extract interactive parts
| Error | Cause | Fix |
|---|---|---|
'use client' must be first | Directive not at line 1 | Move to very first line |
Module not found: @/... | Path alias issue | Check tsconfig paths |
Hydration mismatch | Server/client HTML differs | Ensure same data |
await params | Dynamic route in Next.js 16 | Add await context.params |
Text content mismatch | Date/random on server | Use suppressHydrationWarning or move to client |
| Error | Cause | Fix |
|---|---|---|
Element type is invalid: got undefined | Wrong import/export | Check export type matches import |
mixed up default and named imports | Import mismatch | Pages: import X from, Components: import { X } from |
Import/Export Rules:
app/**/page.tsx): Use export default → Import with import X fromcomponents/*): Use export function X → Import with import { X } from// WRONG - will cause "Element type is invalid"
import HeroSection from '@/components/HeroSection'; // if HeroSection uses named export
// CORRECT
import { HeroSection } from '@/components/HeroSection'; // named export
| Error | Cause | Fix |
|---|---|---|
P1001: Can't reach database | DB not running | Start postgres container |
P2002: Unique constraint | Duplicate entry | Check unique fields |
P2025: Record not found | Delete/update missing | Check ID exists first |
PrismaClient not generated | Missing generate | Run bunx prisma generate |
P2003: Foreign key constraint | Referenced record missing | Create parent first |
Invalid prisma client | Schema changed | Run bunx prisma generate |
console.log('Value:', value);
console.table(arrayOfObjects);
console.trace('Call stack');
console.time('operation');
// ... code ...
console.timeEnd('operation');
// Check type at runtime
console.log('Type:', typeof value);
console.log('Is array:', Array.isArray(value));
console.log('Instance:', value instanceof Date);
// Narrow types
if (typeof value === 'string') {
// value is string here
}
# Find when bug was introduced
git bisect start
git bisect bad HEAD
git bisect good <known-good-commit>
# Check recent changes
git diff HEAD~5
git log --oneline -10
references/error-handling-patterns.md - Toast notifications, form errors, error boundaries