vibe-stack / rules
Cursor rule8 starsChanged 8 months agoMITView on GitHub
Error boundaries, loading states, and server error handling
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository31 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/ai-collaboration.mdcCursor rule
- .cursor/rules/api-design.mdcCursor rule
- .cursor/rules/api-validation.mdcCursor rule
- .cursor/rules/caching-revalidation.mdcCursor rule
- .cursor/rules/context-management.mdcCursor rule
- .cursor/rules/database-design.mdcCursor rule
- .cursor/rules/env-management.mdcCursor rule
- .cursor/rules/file-naming.mdcCursor rule
- .cursor/rules/file-uploads.mdcCursor rule
- .cursor/rules/git-conventions.mdcCursor rule
- .cursor/rules/hydration-safety.mdcCursor rule
- .cursor/rules/middleware-auth.mdcCursor rule
- .cursor/rules/nextjs15-params.mdcCursor rule
- .cursor/rules/performance.mdcCursor rule
- .cursor/rules/project-context.mdcCursor rule
- .cursor/rules/react19-patterns.mdcCursor rule
- .cursor/rules/security.mdcCursor rule
- .cursor/rules/server-actions.mdcCursor rule
- .cursor/rules/server-vs-client-components.mdcCursor rule
- .cursor/rules/shadcn-patterns.mdcCursor rule
- .cursor/rules/stripe-payments.mdcCursor rule
- .cursor/rules/stripe-webhooks.mdcCursor rule
- .cursor/rules/supabase-auth-security.mdcCursor rule
- .cursor/rules/supabase-rls.mdcCursor rule
- .cursor/rules/supabase-ssr-only.mdcCursor rule
- .cursor/rules/testing.mdcCursor rule
- .cursor/rules/typescript-strict.mdcCursor rule
- .cursor/rules/verify-before-use.mdcCursor rule
- llms.txtllms.txt
The file
We split this error-handling.mdc into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
EVERY page in app/ router that does data fetching MUST have:
- Distinctive: line 83
Every Server Action MUST return a typed response — never throw.
- Very specific: line 117
NEVER ignore the error field from Supabase queries.
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: Error boundaries, loading states, and server error handling
globs: ["**/app/**"]
---
# Error Handling and Loading States
## RULE 1: Every Data-Fetching Page Needs Sibling Files
EVERY page in `app/` router that does data fetching MUST have:
- `loading.tsx` (Suspense boundary — shown during streaming)
- `error.tsx` (Error boundary — must be `'use client'`)
`loading.tsx` template:
```tsx
export default function Loading() {
return (
<div className="flex items-center justify-center min-h-[200px]">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary" />
</div>
)
}
```
`error.tsx` template:
```tsx
'use client'
export default function Error({
error,
reset
}: {
error: Error & { digest?: string }
reset: () => void
}) {
return (
<div className="flex flex-col items-center justify-center min-h-[200px] gap-4">
<h2 className="text-xl font-semibold">Something went wrong</h2>
<p className="text-muted-foreground">An unexpected error occurred.</p>
<button
onClick={reset}
className="px-4 py-2 bg-primary text-primary-foreground rounded-md"
>
Try again
</button>
</div>
)
}
```
## RULE 2: NEVER Expose Internal Errors to Clients
Server errors, database errors, and stack traces MUST stay server-side.
Return generic messages to the client. Log the real error.
✅ CORRECT:
```typescript
try {
const { data, error } = await supabase.from('posts').select()
if (error) throw error
return data
} catch (error) {
console.error('[POSTS_FETCH_ERROR]', error) // Detailed log server-side
return NextResponse.json(
{ error: 'Failed to fetch posts' }, // Generic message to client
{ status: 500 }
)
}
```
❌ WRONG:
```typescript
} catch (error) {
return NextResponse.json(
{ error: error.message }, // Leaks: "relation 'posts' does not exist"
{ status: 500 }
)
}
```
## RULE 3: Use ActionResponse for All Server Actions
Every Server Action MUST return a typed response — never throw.
```typescript
type ActionResponse<T = void> =
| { success: true; data: T }
| { success: false; error: string }
// Usage:
export async function createPost(input: unknown): Promise<ActionResponse<Post>> {
const supabase = await createClient()
const { data: { user } } = await supabase.auth.getUser()
if (!user) return { success: false, error: 'Unauthorized' }
const parsed = PostSchema.safeParse(input)
if (!parsed.success) return { success: false, error: 'Invalid input' }
const { data, error } = await supabase
.from('posts')
.insert({ ...parsed.data, user_id: user.id })
.select()
.single()
if (error) {
console.error('[CREATE_POST_ERROR]', error)
return { success: false, error: 'Failed to create post' }
}
revalidatePath('/dashboard')
return { success: true, data }
}
```
## RULE 4: Handle Supabase Errors Explicitly
NEVER ignore the `error` field from Supabase queries.
✅ CORRECT:
```typescript
const { data, error } = await supabase.from('posts').select()
if (error) {
console.error('[SUPABASE_ERROR]', error.message, error.code)
throw new Error('Database query failed')
}
// data is now safely typed as non-null
```
❌ WRONG:
```typescript
const { data } = await supabase.from('posts').select()
// data could be null if query failed — using it causes runtime crash
return data.map(post => post.title) // TypeError: Cannot read property 'map' of null
```
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

