@intentsolutionsio/supabase-pack 1.0.0 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +73 -47
- package/package.json +4 -4
- package/skills/supabase-advanced-troubleshooting/SKILL.md +404 -200
- package/skills/supabase-advanced-troubleshooting/references/errors.md +11 -0
- package/skills/supabase-advanced-troubleshooting/references/evidence-collection-framework.md +34 -0
- package/skills/supabase-advanced-troubleshooting/references/examples.md +11 -0
- package/skills/supabase-advanced-troubleshooting/references/rls-edge-functions-realtime.md +363 -0
- package/skills/supabase-advanced-troubleshooting/references/systematic-isolation.md +56 -0
- package/skills/supabase-advanced-troubleshooting/references/timing-analysis.md +35 -0
- package/skills/supabase-architecture-variants/SKILL.md +395 -216
- package/skills/supabase-architecture-variants/references/errors.md +11 -0
- package/skills/supabase-architecture-variants/references/examples.md +12 -0
- package/skills/supabase-architecture-variants/references/serverless-and-multi-tenant.md +251 -0
- package/skills/supabase-architecture-variants/references/variant-a-monolith-(simple).md +44 -0
- package/skills/supabase-architecture-variants/references/variant-b-service-layer-(moderate).md +72 -0
- package/skills/supabase-architecture-variants/references/variant-c-microservice-(complex).md +81 -0
- package/skills/supabase-auth-storage-realtime-core/SKILL.md +471 -37
- package/skills/supabase-ci-integration/SKILL.md +315 -67
- package/skills/supabase-ci-integration/references/errors.md +10 -0
- package/skills/supabase-ci-integration/references/examples.md +36 -0
- package/skills/supabase-ci-integration/references/implementation.md +54 -0
- package/skills/supabase-common-errors/SKILL.md +320 -62
- package/skills/supabase-common-errors/references/errors.md +53 -0
- package/skills/supabase-common-errors/references/examples.md +23 -0
- package/skills/supabase-cost-tuning/SKILL.md +365 -131
- package/skills/supabase-cost-tuning/references/cost-estimation.md +34 -0
- package/skills/supabase-cost-tuning/references/cost-reduction-strategies.md +40 -0
- package/skills/supabase-cost-tuning/references/errors.md +11 -0
- package/skills/supabase-cost-tuning/references/examples.md +15 -0
- package/skills/supabase-data-handling/SKILL.md +378 -145
- package/skills/supabase-data-handling/references/errors.md +11 -0
- package/skills/supabase-data-handling/references/examples.md +27 -0
- package/skills/supabase-data-handling/references/implementation.md +223 -0
- package/skills/supabase-data-handling/references/retention-and-backup.md +221 -0
- package/skills/supabase-debug-bundle/SKILL.md +267 -73
- package/skills/supabase-debug-bundle/references/errors.md +12 -0
- package/skills/supabase-debug-bundle/references/examples.md +24 -0
- package/skills/supabase-debug-bundle/references/implementation.md +54 -0
- package/skills/supabase-deploy-integration/SKILL.md +258 -147
- package/skills/supabase-deploy-integration/references/errors.md +11 -0
- package/skills/supabase-deploy-integration/references/examples.md +21 -0
- package/skills/supabase-deploy-integration/references/google-cloud-run.md +36 -0
- package/skills/supabase-deploy-integration/references/vercel-deployment.md +35 -0
- package/skills/supabase-enterprise-rbac/SKILL.md +327 -160
- package/skills/supabase-enterprise-rbac/references/api-scoping-and-enforcement.md +255 -0
- package/skills/supabase-enterprise-rbac/references/errors.md +11 -0
- package/skills/supabase-enterprise-rbac/references/examples.md +12 -0
- package/skills/supabase-enterprise-rbac/references/role-implementation.md +33 -0
- package/skills/supabase-enterprise-rbac/references/sso-integration.md +35 -0
- package/skills/supabase-hello-world/SKILL.md +160 -54
- package/skills/supabase-incident-runbook/SKILL.md +453 -131
- package/skills/supabase-incident-runbook/references/errors.md +11 -0
- package/skills/supabase-incident-runbook/references/examples.md +10 -0
- package/skills/supabase-incident-runbook/references/immediate-actions-by-error-type.md +41 -0
- package/skills/supabase-install-auth/SKILL.md +186 -50
- package/skills/supabase-install-auth/references/examples.md +102 -0
- package/skills/supabase-known-pitfalls/SKILL.md +411 -241
- package/skills/supabase-known-pitfalls/references/errors.md +11 -0
- package/skills/supabase-known-pitfalls/references/examples.md +12 -0
- package/skills/supabase-load-scale/SKILL.md +346 -217
- package/skills/supabase-load-scale/references/capacity-planning.md +47 -0
- package/skills/supabase-load-scale/references/errors.md +11 -0
- package/skills/supabase-load-scale/references/examples.md +26 -0
- package/skills/supabase-load-scale/references/load-testing-with-k6.md +59 -0
- package/skills/supabase-load-scale/references/scaling-patterns.md +65 -0
- package/skills/supabase-load-scale/references/table-partitioning.md +263 -0
- package/skills/supabase-local-dev-loop/SKILL.md +272 -73
- package/skills/supabase-local-dev-loop/references/errors.md +11 -0
- package/skills/supabase-local-dev-loop/references/examples.md +21 -0
- package/skills/supabase-local-dev-loop/references/implementation.md +60 -0
- package/skills/supabase-migration-deep-dive/SKILL.md +338 -177
- package/skills/supabase-migration-deep-dive/references/backfill-versioning-rollback.md +258 -0
- package/skills/supabase-migration-deep-dive/references/errors.md +11 -0
- package/skills/supabase-migration-deep-dive/references/examples.md +12 -0
- package/skills/supabase-migration-deep-dive/references/implementation-plan.md +80 -0
- package/skills/supabase-migration-deep-dive/references/pre-migration-assessment.md +39 -0
- package/skills/supabase-multi-env-setup/SKILL.md +393 -152
- package/skills/supabase-multi-env-setup/references/configuration-structure.md +59 -0
- package/skills/supabase-multi-env-setup/references/errors.md +11 -0
- package/skills/supabase-multi-env-setup/references/examples.md +11 -0
- package/skills/supabase-observability/SKILL.md +318 -196
- package/skills/supabase-observability/references/alert-configuration.md +40 -0
- package/skills/supabase-observability/references/errors.md +11 -0
- package/skills/supabase-observability/references/examples.md +13 -0
- package/skills/supabase-observability/references/metrics-collection.md +65 -0
- package/skills/supabase-performance-tuning/SKILL.md +304 -160
- package/skills/supabase-performance-tuning/references/caching-strategy.md +49 -0
- package/skills/supabase-performance-tuning/references/errors.md +11 -0
- package/skills/supabase-performance-tuning/references/examples.md +13 -0
- package/skills/supabase-policy-guardrails/SKILL.md +248 -221
- package/skills/supabase-policy-guardrails/references/ci-cost-security.md +484 -0
- package/skills/supabase-policy-guardrails/references/errors.md +11 -0
- package/skills/supabase-policy-guardrails/references/eslint-rules.md +46 -0
- package/skills/supabase-policy-guardrails/references/examples.md +10 -0
- package/skills/supabase-prod-checklist/SKILL.md +474 -84
- package/skills/supabase-prod-checklist/references/errors.md +63 -0
- package/skills/supabase-prod-checklist/references/examples.md +153 -0
- package/skills/supabase-prod-checklist/references/implementation.md +113 -0
- package/skills/supabase-rate-limits/SKILL.md +311 -98
- package/skills/supabase-rate-limits/references/errors.md +11 -0
- package/skills/supabase-rate-limits/references/examples.md +46 -0
- package/skills/supabase-rate-limits/references/implementation.md +66 -0
- package/skills/supabase-reference-architecture/SKILL.md +249 -182
- package/skills/supabase-reference-architecture/references/errors.md +29 -0
- package/skills/supabase-reference-architecture/references/examples.md +116 -0
- package/skills/supabase-reference-architecture/references/key-components.md +244 -0
- package/skills/supabase-reference-architecture/references/project-structure.md +109 -0
- package/skills/supabase-reliability-patterns/SKILL.md +229 -234
- package/skills/supabase-reliability-patterns/references/circuit-breaker.md +36 -0
- package/skills/supabase-reliability-patterns/references/dead-letter-queue.md +48 -0
- package/skills/supabase-reliability-patterns/references/errors.md +11 -0
- package/skills/supabase-reliability-patterns/references/examples.md +11 -0
- package/skills/supabase-reliability-patterns/references/idempotency-keys.md +36 -0
- package/skills/supabase-reliability-patterns/references/offline-degradation-health-dualwrite.md +489 -0
- package/skills/supabase-schema-from-requirements/SKILL.md +373 -34
- package/skills/supabase-sdk-patterns/SKILL.md +388 -99
- package/skills/supabase-sdk-patterns/references/errors.md +11 -0
- package/skills/supabase-sdk-patterns/references/examples.md +45 -0
- package/skills/supabase-sdk-patterns/references/implementation.md +67 -0
- package/skills/supabase-security-basics/SKILL.md +282 -102
- package/skills/supabase-security-basics/references/errors.md +10 -0
- package/skills/supabase-security-basics/references/examples.md +70 -0
- package/skills/supabase-security-basics/references/implementation.md +39 -0
- package/skills/supabase-upgrade-migration/SKILL.md +248 -66
- package/skills/supabase-upgrade-migration/references/errors.md +10 -0
- package/skills/supabase-upgrade-migration/references/examples.md +51 -0
- package/skills/supabase-upgrade-migration/references/implementation.md +29 -0
- package/skills/supabase-webhooks-events/SKILL.md +412 -138
- package/skills/supabase-webhooks-events/references/errors.md +55 -0
- package/skills/supabase-webhooks-events/references/event-handler-pattern.md +106 -0
- package/skills/supabase-webhooks-events/references/examples.md +133 -0
- package/skills/supabase-webhooks-events/references/signature-verification.md +165 -0
|
@@ -1,109 +1,367 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: supabase-common-errors
|
|
3
|
-
description:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
or
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
description: 'Diagnose and fix Supabase errors across PostgREST, PostgreSQL, Auth,
|
|
4
|
+
Storage, and Realtime.
|
|
5
|
+
|
|
6
|
+
Use when encountering error codes like PGRST301, 42501, 23505, or auth failures.
|
|
7
|
+
|
|
8
|
+
Use when debugging failed queries, RLS policy violations, or HTTP 4xx/5xx responses.
|
|
9
|
+
|
|
10
|
+
Trigger with "supabase error", "fix supabase", "PGRST", "supabase 403", "RLS not
|
|
11
|
+
working",
|
|
12
|
+
|
|
13
|
+
"supabase auth error", "unique constraint", "foreign key violation".
|
|
14
|
+
|
|
15
|
+
'
|
|
16
|
+
allowed-tools: Read, Grep, Bash(curl:*), Bash(supabase:*), Bash(npx:*)
|
|
10
17
|
version: 1.0.0
|
|
11
18
|
license: MIT
|
|
12
19
|
author: Jeremy Longshore <jeremy@intentsolutions.io>
|
|
20
|
+
tags:
|
|
21
|
+
- saas
|
|
22
|
+
- supabase
|
|
23
|
+
- debugging
|
|
24
|
+
- errors
|
|
25
|
+
- postgrest
|
|
26
|
+
- rls
|
|
27
|
+
- auth
|
|
28
|
+
compatibility: Designed for Claude Code, also compatible with Codex and OpenClaw
|
|
13
29
|
---
|
|
14
|
-
|
|
15
30
|
# Supabase Common Errors
|
|
16
31
|
|
|
17
32
|
## Overview
|
|
18
|
-
|
|
33
|
+
|
|
34
|
+
Diagnostic guide for Supabase errors across PostgREST (`PGRST*`), PostgreSQL (numeric codes), Auth, Storage, and Realtime. Identify the error layer, trace the root cause, and apply the correct fix — every SDK call returns `{ data, error }` where `data` is null when `error` exists.
|
|
19
35
|
|
|
20
36
|
## Prerequisites
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
37
|
+
|
|
38
|
+
- `@supabase/supabase-js` installed (`npm install @supabase/supabase-js`)
|
|
39
|
+
- `SUPABASE_URL` and `SUPABASE_ANON_KEY` (or `SUPABASE_SERVICE_ROLE_KEY`) configured
|
|
40
|
+
- Access to Supabase Dashboard (for log inspection and SQL Editor)
|
|
41
|
+
- Supabase CLI installed for local development (`npx supabase --version`)
|
|
24
42
|
|
|
25
43
|
## Instructions
|
|
26
44
|
|
|
27
|
-
### Step 1
|
|
28
|
-
Check error message and code in your logs or console.
|
|
45
|
+
### Step 1 — Capture the Error Object
|
|
29
46
|
|
|
30
|
-
|
|
31
|
-
Match your error to one of the documented cases.
|
|
47
|
+
Every Supabase SDK call returns a `{ data, error }` tuple. Never assume `data` exists — always check `error` first.
|
|
32
48
|
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
```typescript
|
|
50
|
+
import { createClient } from '@supabase/supabase-js'
|
|
35
51
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
52
|
+
const supabase = createClient(
|
|
53
|
+
process.env.SUPABASE_URL!,
|
|
54
|
+
process.env.SUPABASE_ANON_KEY!
|
|
55
|
+
)
|
|
40
56
|
|
|
41
|
-
|
|
57
|
+
// WRONG — data is null when error exists
|
|
58
|
+
const { data } = await supabase.from('todos').select('*')
|
|
59
|
+
console.log(data.length) // TypeError: Cannot read property 'length' of null
|
|
42
60
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
61
|
+
// CORRECT — always check error first
|
|
62
|
+
const { data, error } = await supabase.from('todos').select('*')
|
|
63
|
+
if (error) {
|
|
64
|
+
console.error(`[${error.code}] ${error.message}`)
|
|
65
|
+
console.error('Details:', error.details)
|
|
66
|
+
console.error('Hint:', error.hint)
|
|
67
|
+
// error.code tells you the layer:
|
|
68
|
+
// PGRST* = PostgREST (API gateway)
|
|
69
|
+
// 5-digit numeric = PostgreSQL (database)
|
|
70
|
+
// AuthApiError = Auth service
|
|
71
|
+
// StorageApiError = Storage service
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
// Safe to use data here
|
|
75
|
+
console.log(`Found ${data.length} rows`)
|
|
47
76
|
```
|
|
48
77
|
|
|
49
|
-
**
|
|
78
|
+
**Troubleshooting:** If `error` is undefined (not null), you may be using an older SDK version. Upgrade to `@supabase/supabase-js@2.x` or later.
|
|
79
|
+
|
|
80
|
+
### Step 2 — Identify the Error Layer and Code
|
|
81
|
+
|
|
82
|
+
Match the error code prefix to the correct subsystem, then look up the specific code in the tables below.
|
|
83
|
+
|
|
84
|
+
**PostgREST errors** start with `PGRST` and correspond to API-layer issues (JWT, query parsing, schema).
|
|
85
|
+
**PostgreSQL errors** are 5-character codes (e.g., `42501`, `23505`) from the database engine.
|
|
86
|
+
**Auth errors** come as `AuthApiError` with a human-readable message.
|
|
87
|
+
**Storage errors** come as `StorageApiError` with an HTTP status.
|
|
50
88
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
89
|
+
```typescript
|
|
90
|
+
// Diagnostic helper — paste into your codebase to classify errors automatically
|
|
91
|
+
function diagnoseSupabaseError(error: { code?: string; message: string; status?: number }) {
|
|
92
|
+
if (!error) return 'No error'
|
|
93
|
+
|
|
94
|
+
if (error.code?.startsWith('PGRST')) {
|
|
95
|
+
return `PostgREST error ${error.code}: ${error.message}\n` +
|
|
96
|
+
'Check: JWT validity, column/table names, query syntax'
|
|
97
|
+
}
|
|
98
|
+
if (error.code && /^\d{5}$/.test(error.code)) {
|
|
99
|
+
return `PostgreSQL error ${error.code}: ${error.message}\n` +
|
|
100
|
+
'Check: RLS policies, constraints, schema migrations'
|
|
101
|
+
}
|
|
102
|
+
if (error.message?.includes('AuthApiError')) {
|
|
103
|
+
return `Auth error: ${error.message}\n` +
|
|
104
|
+
'Check: credentials, email confirmation, token expiry'
|
|
105
|
+
}
|
|
106
|
+
if (error.message?.includes('StorageApiError')) {
|
|
107
|
+
return `Storage error: ${error.message}\n` +
|
|
108
|
+
'Check: bucket exists, RLS on storage.objects, file size limits'
|
|
109
|
+
}
|
|
110
|
+
return `Unknown error: ${JSON.stringify(error)}`
|
|
111
|
+
}
|
|
54
112
|
```
|
|
55
113
|
|
|
56
|
-
|
|
114
|
+
**Troubleshooting:** If the error code is empty or missing, check the HTTP status code on the response. A `401` without a code usually means `SUPABASE_ANON_KEY` is wrong or missing. A `500` without a code usually means a database function threw an unhandled exception.
|
|
115
|
+
|
|
116
|
+
### Step 3 — Apply the Fix and Verify
|
|
117
|
+
|
|
118
|
+
Once you have identified the error code, apply the corresponding fix from the Error Handling table. Then verify the fix by re-running the original operation.
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
// Example: Fix PGRST301 (JWT expired)
|
|
122
|
+
// Before: stale session causes 401
|
|
123
|
+
const { data, error } = await supabase.from('todos').select('*')
|
|
124
|
+
// error.code === 'PGRST301'
|
|
125
|
+
|
|
126
|
+
// Fix: refresh the session, then retry
|
|
127
|
+
const { error: refreshError } = await supabase.auth.refreshSession()
|
|
128
|
+
if (refreshError) {
|
|
129
|
+
// Token is fully invalid — force re-login
|
|
130
|
+
await supabase.auth.signOut()
|
|
131
|
+
console.error('Session expired. Please sign in again.')
|
|
132
|
+
return
|
|
133
|
+
}
|
|
57
134
|
|
|
58
|
-
|
|
59
|
-
|
|
135
|
+
// Retry the original query
|
|
136
|
+
const { data: retryData, error: retryError } = await supabase.from('todos').select('*')
|
|
137
|
+
if (retryError) {
|
|
138
|
+
console.error('Still failing after refresh:', retryError.code, retryError.message)
|
|
139
|
+
} else {
|
|
140
|
+
console.log('Fixed! Retrieved', retryData.length, 'rows')
|
|
141
|
+
}
|
|
60
142
|
```
|
|
61
|
-
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
// Example: Fix 42501 (RLS policy violation)
|
|
146
|
+
// Step A: Confirm RLS is the problem using service role client
|
|
147
|
+
const adminClient = createClient(
|
|
148
|
+
process.env.SUPABASE_URL!,
|
|
149
|
+
process.env.SUPABASE_SERVICE_ROLE_KEY!, // bypasses RLS
|
|
150
|
+
{ auth: { autoRefreshToken: false, persistSession: false } }
|
|
151
|
+
)
|
|
152
|
+
const { data: adminData } = await adminClient.from('todos').select('*')
|
|
153
|
+
console.log('Admin sees', adminData?.length, 'rows') // If this works, RLS is blocking
|
|
154
|
+
|
|
155
|
+
// Step B: Check which user the JWT resolves to
|
|
156
|
+
const { data: { user } } = await supabase.auth.getUser()
|
|
157
|
+
console.log('Current auth.uid() =', user?.id)
|
|
158
|
+
|
|
159
|
+
// Step C: Fix the RLS policy in SQL Editor or migration
|
|
160
|
+
/*
|
|
161
|
+
CREATE POLICY "Users can read own todos"
|
|
162
|
+
ON todos FOR SELECT
|
|
163
|
+
USING (auth.uid() = user_id);
|
|
164
|
+
|
|
165
|
+
-- Verify with:
|
|
166
|
+
SET request.jwt.claim.sub = '<user-id>';
|
|
167
|
+
SELECT * FROM todos;
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
// Step D: Retry original query
|
|
171
|
+
const { data: fixedData, error: fixedError } = await supabase.from('todos').select('*')
|
|
172
|
+
console.log(fixedError ? `Still blocked: ${fixedError.code}` : `Success: ${fixedData.length} rows`)
|
|
62
173
|
```
|
|
63
174
|
|
|
64
|
-
**
|
|
175
|
+
**Troubleshooting:** After applying a migration, you may need to reload the PostgREST schema cache. In the Supabase Dashboard, go to Settings > API and click "Reload schema cache", or call `NOTIFY pgrst, 'reload schema'` in SQL.
|
|
176
|
+
|
|
177
|
+
## Output
|
|
65
178
|
|
|
66
|
-
|
|
67
|
-
Check RLS policies in dashboard or via pg_policies table. Ensure user has required role.
|
|
179
|
+
Deliverables after applying this skill:
|
|
68
180
|
|
|
69
|
-
|
|
181
|
+
- Error identified by code and layer (PostgREST, PostgreSQL, Auth, Storage, Realtime)
|
|
182
|
+
- Root cause isolated using the diagnostic helper or manual code inspection
|
|
183
|
+
- Fix applied from the Error Handling table and verified against the original failing operation
|
|
184
|
+
- Guard code in place (`if (error)` checks) preventing silent null-data bugs
|
|
185
|
+
|
|
186
|
+
## Error Handling
|
|
187
|
+
|
|
188
|
+
### PostgREST API Errors (PGRST*)
|
|
189
|
+
|
|
190
|
+
| Code | HTTP | Meaning | Root Cause | Fix |
|
|
191
|
+
|------|------|---------|------------|-----|
|
|
192
|
+
| `PGRST301` | 401 | JWT expired or invalid | `SUPABASE_ANON_KEY` is wrong, or the user session expired | Verify `SUPABASE_ANON_KEY` matches the project; call `supabase.auth.refreshSession()` |
|
|
193
|
+
| `PGRST302` | 401 | Missing Authorization header | Client created without a key, or middleware stripped the header | Pass `SUPABASE_ANON_KEY` to `createClient()`; check proxy/CDN config |
|
|
194
|
+
| `PGRST116` | 406 | No rows returned for `.single()` | Query matched 0 rows but `.single()` expects exactly 1 | Use `.maybeSingle()` for optional lookups, or check filters |
|
|
195
|
+
| `PGRST200` | 400 | Invalid query parameters | Malformed filter, bad operator, or invalid column reference | Check filter syntax: `.eq('col', val)` not `.eq('col = val')` |
|
|
196
|
+
| `PGRST204` | 400 | Column not found | Column name doesn't exist in the table or view | Verify column exists with `supabase gen types typescript`; check for typos |
|
|
197
|
+
| `PGRST000` | 503 | Connection pool exhausted | Too many concurrent connections from serverless functions | Enable pgBouncer (Supavisor) in project settings; reduce connection count |
|
|
198
|
+
|
|
199
|
+
### PostgreSQL Database Errors (5-digit codes)
|
|
200
|
+
|
|
201
|
+
| Code | Meaning | Root Cause | Fix |
|
|
202
|
+
|------|---------|------------|-----|
|
|
203
|
+
| `42501` | RLS policy violation | Row-level security is blocking the operation for this user | Add or fix the RLS policy; test with service role to confirm |
|
|
204
|
+
| `23505` | Unique constraint violation | INSERT/UPDATE conflicts with an existing row | Use `.upsert({ onConflict: 'column' })` or check existence first |
|
|
205
|
+
| `23503` | Foreign key violation | Referenced row doesn't exist in the parent table | Insert the parent row first, or check the foreign key value |
|
|
206
|
+
| `42P01` | Table or relation doesn't exist | Migration not applied, or wrong schema | Run `supabase db push`; verify schema with `\dt` in SQL Editor |
|
|
207
|
+
| `42703` | Column doesn't exist | Schema out of sync with code | Regenerate types: `supabase gen types typescript --local > types/supabase.ts` |
|
|
208
|
+
| `57014` | Query cancelled (statement timeout) | Query took longer than `statement_timeout` | Add indexes; simplify the query; increase timeout in `postgresql.conf` |
|
|
209
|
+
|
|
210
|
+
### Auth Service Errors
|
|
211
|
+
|
|
212
|
+
| Error Message | Cause | Fix |
|
|
213
|
+
|---------------|-------|-----|
|
|
214
|
+
| `invalid_credentials` / `Invalid login credentials` | Wrong email or password | Verify credentials; check if email is confirmed |
|
|
215
|
+
| `email_not_confirmed` / `Email not confirmed` | User hasn't clicked confirmation link | Check inbox/spam; for local dev check Inbucket at `localhost:54324` |
|
|
216
|
+
| `user_already_exists` / `User already registered` | Duplicate sign-up | Call `signInWithPassword()` instead of `signUp()` |
|
|
217
|
+
| `Token has expired or is invalid` | Stale magic link or OTP | Request a new magic link or OTP; links expire after 5 minutes by default |
|
|
218
|
+
| `AuthRetryableFetchError` | Network failure reaching Auth service | Retry with backoff; verify `SUPABASE_URL` is correct and reachable |
|
|
219
|
+
|
|
220
|
+
### Storage Errors
|
|
221
|
+
|
|
222
|
+
| Error | Cause | Fix |
|
|
223
|
+
|-------|-------|-----|
|
|
224
|
+
| `Bucket not found` | Bucket name is wrong or bucket doesn't exist | Create the bucket in Dashboard or via migration SQL |
|
|
225
|
+
| `The resource already exists` | Uploading to a path that already has a file | Pass `{ upsert: true }` in upload options to overwrite |
|
|
226
|
+
| `new row violates row-level security` | Storage RLS blocking the upload/download | Add a policy on `storage.objects` for the operation (INSERT, SELECT, DELETE) |
|
|
227
|
+
| `413 Payload Too Large` | File exceeds the bucket's size limit | Increase `file_size_limit` on the bucket, or use TUS resumable upload for large files |
|
|
228
|
+
|
|
229
|
+
### Realtime Errors
|
|
230
|
+
|
|
231
|
+
| Symptom | Cause | Fix |
|
|
232
|
+
|---------|-------|-----|
|
|
233
|
+
| `CHANNEL_ERROR` on subscribe | Realtime not enabled for the table | Dashboard > Database > Replication > enable the table; or add it to `supabase_realtime` publication |
|
|
234
|
+
| `TIMED_OUT` on subscribe | Network issue or firewall blocking WebSocket | Check that port 443 WebSocket connections are allowed |
|
|
235
|
+
| No events received | Table not in Realtime publication | Run: `ALTER PUBLICATION supabase_realtime ADD TABLE your_table;` |
|
|
236
|
+
| Events stop after deploy | Schema change drops Realtime connections | Clients auto-reconnect; ensure `.subscribe()` handles reconnection |
|
|
237
|
+
|
|
238
|
+
## Examples
|
|
239
|
+
|
|
240
|
+
### Example 1 — Handling `.single()` on optional data (PGRST116)
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
// BAD — crashes when user has no profile
|
|
244
|
+
const { data: profile } = await supabase
|
|
245
|
+
.from('profiles')
|
|
246
|
+
.select('*')
|
|
247
|
+
.eq('user_id', userId)
|
|
248
|
+
.single() // throws PGRST116 if no row exists
|
|
70
249
|
|
|
71
|
-
|
|
72
|
-
|
|
250
|
+
// GOOD — returns null instead of erroring
|
|
251
|
+
const { data: profile, error } = await supabase
|
|
252
|
+
.from('profiles')
|
|
253
|
+
.select('*')
|
|
254
|
+
.eq('user_id', userId)
|
|
255
|
+
.maybeSingle()
|
|
256
|
+
|
|
257
|
+
if (!profile) {
|
|
258
|
+
// Create a default profile
|
|
259
|
+
const { data: newProfile } = await supabase
|
|
260
|
+
.from('profiles')
|
|
261
|
+
.insert({ user_id: userId, display_name: 'New User' })
|
|
262
|
+
.select()
|
|
263
|
+
.single()
|
|
264
|
+
}
|
|
73
265
|
```
|
|
74
|
-
|
|
266
|
+
|
|
267
|
+
### Example 2 — Upsert to avoid unique constraint (23505)
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
// BAD — fails if row already exists
|
|
271
|
+
const { error } = await supabase
|
|
272
|
+
.from('user_settings')
|
|
273
|
+
.insert({ user_id: userId, theme: 'dark' })
|
|
274
|
+
// error.code === '23505' — unique constraint on user_id
|
|
275
|
+
|
|
276
|
+
// GOOD — inserts or updates based on conflict column
|
|
277
|
+
const { data, error } = await supabase
|
|
278
|
+
.from('user_settings')
|
|
279
|
+
.upsert(
|
|
280
|
+
{ user_id: userId, theme: 'dark' },
|
|
281
|
+
{ onConflict: 'user_id' }
|
|
282
|
+
)
|
|
283
|
+
.select()
|
|
284
|
+
.single()
|
|
75
285
|
```
|
|
76
286
|
|
|
77
|
-
|
|
287
|
+
### Example 3 — Realtime subscription with error handling
|
|
78
288
|
|
|
79
|
-
**Solution:**
|
|
80
289
|
```typescript
|
|
81
|
-
|
|
290
|
+
const channel = supabase
|
|
291
|
+
.channel('todos-changes')
|
|
292
|
+
.on(
|
|
293
|
+
'postgres_changes',
|
|
294
|
+
{ event: '*', schema: 'public', table: 'todos' },
|
|
295
|
+
(payload) => {
|
|
296
|
+
console.log('Change received:', payload.eventType, payload.new)
|
|
297
|
+
}
|
|
298
|
+
)
|
|
299
|
+
.subscribe((status, err) => {
|
|
300
|
+
switch (status) {
|
|
301
|
+
case 'SUBSCRIBED':
|
|
302
|
+
console.log('Realtime connected')
|
|
303
|
+
break
|
|
304
|
+
case 'CHANNEL_ERROR':
|
|
305
|
+
console.error('Realtime error — is the table in the publication?', err)
|
|
306
|
+
// Fix: ALTER PUBLICATION supabase_realtime ADD TABLE todos;
|
|
307
|
+
break
|
|
308
|
+
case 'TIMED_OUT':
|
|
309
|
+
console.error('Realtime timed out — check network')
|
|
310
|
+
break
|
|
311
|
+
case 'CLOSED':
|
|
312
|
+
console.log('Channel closed')
|
|
313
|
+
break
|
|
314
|
+
}
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
// Always clean up on unmount / exit
|
|
318
|
+
process.on('SIGINT', async () => {
|
|
319
|
+
await supabase.removeChannel(channel)
|
|
320
|
+
process.exit(0)
|
|
321
|
+
})
|
|
82
322
|
```
|
|
83
323
|
|
|
84
|
-
|
|
324
|
+
### Example 4 — Connection pool exhaustion (PGRST000) in serverless
|
|
85
325
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
326
|
+
```typescript
|
|
327
|
+
// BAD — creates a new client per request in serverless (Lambda, Edge Functions)
|
|
328
|
+
export async function handler(req: Request) {
|
|
329
|
+
const supabase = createClient(url, key) // new connection every invocation
|
|
330
|
+
const { data } = await supabase.from('todos').select('*')
|
|
331
|
+
return Response.json(data)
|
|
332
|
+
}
|
|
90
333
|
|
|
91
|
-
|
|
92
|
-
|
|
334
|
+
// GOOD — reuse client across warm invocations
|
|
335
|
+
const supabase = createClient(url, key, {
|
|
336
|
+
auth: { autoRefreshToken: false, persistSession: false }
|
|
337
|
+
})
|
|
93
338
|
|
|
94
|
-
|
|
95
|
-
|
|
339
|
+
export async function handler(req: Request) {
|
|
340
|
+
const { data, error } = await supabase.from('todos').select('*')
|
|
341
|
+
if (error) {
|
|
342
|
+
if (error.code === 'PGRST000') {
|
|
343
|
+
// Pool exhausted — return 503 so the caller retries
|
|
344
|
+
return new Response('Service temporarily unavailable', { status: 503 })
|
|
345
|
+
}
|
|
346
|
+
return Response.json({ error: error.message }, { status: 400 })
|
|
347
|
+
}
|
|
348
|
+
return Response.json(data)
|
|
349
|
+
}
|
|
96
350
|
```
|
|
97
351
|
|
|
98
|
-
### Escalation Path
|
|
99
|
-
1. Collect evidence with `supabase-debug-bundle`
|
|
100
|
-
2. Check Supabase status page
|
|
101
|
-
3. Contact support with request ID
|
|
102
|
-
|
|
103
352
|
## Resources
|
|
353
|
+
|
|
354
|
+
- [Supabase JavaScript SDK Reference](https://supabase.com/docs/reference/javascript/introduction)
|
|
355
|
+
- [PostgREST Error Codes](https://postgrest.org/en/stable/references/errors.html)
|
|
356
|
+
- [PostgreSQL Error Codes](https://www.postgresql.org/docs/current/errcodes-appendix.html)
|
|
357
|
+
- Supabase Auth Error Handling
|
|
358
|
+
- [RLS Debugging Guide](https://supabase.com/docs/guides/database/postgres/row-level-security)
|
|
359
|
+
- [Supabase Realtime Troubleshooting](https://supabase.com/docs/guides/realtime/troubleshooting)
|
|
104
360
|
- [Supabase Status Page](https://status.supabase.com)
|
|
105
|
-
- [Supabase Support](https://supabase.com/docs/support)
|
|
106
|
-
- [Supabase Error Codes](https://supabase.com/docs/errors)
|
|
107
361
|
|
|
108
362
|
## Next Steps
|
|
109
|
-
|
|
363
|
+
|
|
364
|
+
- Use `supabase-debug-bundle` to generate a full diagnostic snapshot when errors persist after applying these fixes.
|
|
365
|
+
- Use `supabase-security-basics` to audit your RLS policies and prevent `42501` errors proactively.
|
|
366
|
+
- Use `supabase-known-pitfalls` for edge cases and SDK behavior that can cause subtle bugs.
|
|
367
|
+
- Use `supabase-observability` to set up logging and alerting so you catch errors before users report them.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
## Error Handling Reference
|
|
2
|
+
|
|
3
|
+
### Invalid JWT
|
|
4
|
+
|
|
5
|
+
**Error Message:**
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Invalid JWT: expired or malformed
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
**Cause:** JWT token has expired or is incorrectly formatted
|
|
12
|
+
|
|
13
|
+
**Solution:**
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
Check token expiry with supabase.auth.getSession() and call refreshSession() if needed
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
### RLS Policy Violation
|
|
22
|
+
|
|
23
|
+
**Error Message:**
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
new row violates row-level security policy for table
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Cause:** Row Level Security (RLS) policy is blocking the operation
|
|
30
|
+
|
|
31
|
+
**Solution:**
|
|
32
|
+
Check RLS policies in dashboard or via pg_policies table. Ensure user has required role.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
### Connection Pool Exhausted
|
|
37
|
+
|
|
38
|
+
**Error Message:**
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
too many clients already
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Cause:** Connection pool limit reached due to too many concurrent connections
|
|
45
|
+
|
|
46
|
+
**Solution:**
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
Use connection pooling mode in Supabase dashboard. Switch to Session mode or pgBouncer.
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
*[Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)*
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
## Examples
|
|
2
|
+
|
|
3
|
+
### Quick Diagnostic Commands
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# Check Supabase status
|
|
7
|
+
curl -s https://status.supabase.com
|
|
8
|
+
|
|
9
|
+
# Verify API connectivity
|
|
10
|
+
curl -I https://api.supabase.com
|
|
11
|
+
|
|
12
|
+
# Check local configuration
|
|
13
|
+
env | grep SUPABASE
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Escalation Path
|
|
17
|
+
|
|
18
|
+
1. Collect evidence with `supabase-debug-bundle`
|
|
19
|
+
2. Check Supabase status page
|
|
20
|
+
3. Contact support with request ID
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
*[Tons of Skills](https://tonsofskills.com) by [Intent Solutions](https://intentsolutions.io) | [jeremylongshore.com](https://jeremylongshore.com)*
|