mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
Closes FE-3966 ## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## Problem - The admonition uses both 'tip' and 'note', but the visual distinction has long-ago collapsed. - 'Note' is used far more frequently than 'tip' - The two are very similar and it is confusing to know which one to use when they are visually identical ## Solution Collapse 'tip' and 'note' into one by removing all places where there is 'tip' and updating all references to 'tip' into 'note'. **Note:** This PR also resolves new broken links flagged by the E2E docs checker. It may move to another PR since E2Es keep erroring. ### Specific changes See below for an AI-generated list of changes: - **Type system** — removed `'tip'` from `AdmonitionType`, its `TYPE_TO_VARIANT`/`TYPE_LABEL` entries, and the test case in [`packages/ui-patterns/src/Admonition/](packages/ui-patterns/src/Admonition/) - **Remark plugin** — [remarkAdmonition.ts](apps/docs/lib/mdx/plugins/remarkAdmonition.ts) now maps mkdocs `tip` → `note` - **Lint allowlist** — `tip` dropped from `supa-mdx-lint.config.toml` - **Content migration** — all 109 files with `type="tip"` (across `apps/docs`, `apps/www`, `apps/studio`) converted to `type="note"`; zero remaining hits confirmed by repo-wide grep - **Style guide** — `CONTRIBUTING.md` and `contributing/content.mdx` updated to describe 4 admonition types instead of 5 ### Usage before implementation See the usage table that points toward 'note' as being dominant across all apps: Here's the usage table: | Location | `note` | `tip` | |---|---|---| | apps/docs | ~480 | ~143 | | apps/studio | 34 | 6 | | apps/www (blog) | 19 | 3 | | packages/ui-patterns (tests) | 3 | 1 (parametrized) | | design-system / ui-library / packages/ui / packages/common | 0–1 (test fixture only) | 0 | ## Preview links | App | Page | Search text (Ctrl+F) | Verify | |---|---|---|---| | docs | [/docs/guides/ai-tools/byo-mcp](https://docs-git-admonition-collapse-note-tip-supabase.vercel.app/docs/guides/ai-tools/byo-mcp) | official MCP TypeScript SDK | callout's aria-label="Note" | | docs | [/docs/guides/ai-tools/mcp](https://docs-git-admonition-collapse-note-tip-supabase.vercel.app/docs/guides/ai-tools/mcp) | MCP server is available at | callout's aria-label="Note" | | docs | [/docs/guides/ai/python-clients](https://docs-git-admonition-collapse-note-tip-supabase.vercel.app/docs/guides/ai/python-clients) | Click Connect at the top of any project page | callout's aria-label="Note" | | docs | [/docs/guides/auth/audit-logs](https://docs-git-admonition-collapse-note-tip-supabase.vercel.app/docs/guides/auth/audit-logs) | Disabling Postgres storage reduces your database storage costs | callout's aria-label="Note" | | docs | [/docs/guides/database/tables](https://docs-git-admonition-collapse-note-tip-supabase.vercel.app/docs/guides/database/tables) | access a custom schema through the Supabase Data API | callout's aria-label="Note" | | docs | [/docs/guides/troubleshooting/edge-function-404-error-response](https://docs-git-admonition-collapse-note-tip-supabase.vercel.app/docs/guides/troubleshooting/edge-function-404-error-response) | Always configure an appropriate time frame | callout's aria-label="Note" (was single-quoted type='tip') | | www | [blog: cli-v2-config-as-code](https://zone-www-dot-com-git-admonition-collapse-note-tip-supabase.vercel.app/blog/cli-v2-config-as-code) | Detecting config drift | callout's aria-label="Note" | | www | [blog: cli-v2-config-as-code](https://zone-www-dot-com-git-admonition-collapse-note-tip-supabase.vercel.app/blog/cli-v2-config-as-code) | Setting Edge Function secrets | callout's aria-label="Note" | | www | [blog: nosql-mongodb-compatibility-with-ferretdb-and-flydotio](https://zone-www-dot-com-git-admonition-collapse-note-tip-supabase.vercel.app/blog/nosql-mongodb-compatibility-with-ferretdb-and-flydotio) | If your network supports IPv6 connections | callout's aria-label="Note" | Note: the `www` rows use the `zone-www-dot-com` preview host, not the `docs` one you gave — since blog pages are served from the www app, not docs. ## Manual testing 1. Open preview links for affected pages. 2. Inspect. Open console. 3. Paste the following in and see there is no 'Tip' on the page: ``` document.querySelectorAll('[role="alert"]').forEach(el => console.log(el.getAttribute('aria-label'), el.textContent.slice(0,60))) ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Standardized informational callouts across docs and tutorials from **“Tip”** to **“Note”**, updating multiple examples and guidance blocks. * Updated a few related doc references/links and conditional “Next steps” content. * **UI Updates** * Switched various in-app banners and notices to the **“Note”** style variant. * **Bug Fixes / Improvements** * Removed support for the retired **“Tip”** callout type and aligned docs linting, component behavior, and aria labeling to the remaining admonition types. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
146 lines
5.3 KiB
Plaintext
146 lines
5.3 KiB
Plaintext
---
|
|
id: handling-errors-in-supabase-js
|
|
title: 'Handling errors in `supabase-js`'
|
|
subtitle: 'Read `error.hint` first — Postgres often tells you the exact fix. Log the full error so you actually see it.'
|
|
---
|
|
|
|
Every `supabase-js` call returns a `{ data, error }` pair instead of throwing. When something fails, the single most useful field on `error` is usually `hint` — Postgres returns the _fix_, not only a description of the problem. Logging only `error.message` hides it.
|
|
|
|
## Usage of `message` and `hint` properties
|
|
|
|
Consider a `42501` permission-denied error on a table where default `GRANT`s have been revoked from `anon`:
|
|
|
|
```
|
|
message: "permission denied for table users"
|
|
hint: "Grant the required privileges to the current role with: GRANT SELECT ON public.users TO anon;"
|
|
```
|
|
|
|
The `message` exposes the error reason, and `hint` gives you the literal SQL statement to run in the dashboard SQL editor to fix it.
|
|
|
|
The same pattern shows up across many Postgres errors — missing column? `hint` suggests the column name you probably meant. Type mismatch? `hint` shows the expected type. Whenever Postgres knows the fix, it puts it in `hint`.
|
|
|
|
<Admonition type="note">Log the full `error` object, not only `error.message`.</Admonition>
|
|
|
|
## The recommended pattern
|
|
|
|
Read `{ data, error }` from the response, check `error`, log the whole object, and return early.
|
|
|
|
```ts
|
|
const { data, error } = await supabase.from('users').select()
|
|
if (error) {
|
|
console.error(error)
|
|
return
|
|
}
|
|
```
|
|
|
|
In the case of a permission-denied error, the response body will look like this:
|
|
|
|
```json
|
|
{
|
|
"error": {
|
|
"code": "42501",
|
|
"message": "permission denied for table users",
|
|
"details": null,
|
|
"hint": "Grant the required privileges to the current role with: GRANT SELECT ON public.users TO anon;"
|
|
},
|
|
"status": 401,
|
|
"statusText": "Unauthorized"
|
|
}
|
|
```
|
|
|
|
`postgrest-js` passes the body through verbatim, so `error.hint` is the exact string Postgres produced. Treat it as the answer the database is giving you, not as a suggestion to file away.
|
|
|
|
## The `PostgrestError` fields, by usefulness
|
|
|
|
Database calls (`select`, `insert`, `update`, `upsert`, `delete`, `rpc`) return a `PostgrestError` with four fields. Read them in roughly this order:
|
|
|
|
| Field | Read it when |
|
|
| --------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
| `hint` | Always check first. When Postgres includes one, it's the actionable fix (a `GRANT` to run, a column name, a type). |
|
|
| `code` | When branching in code. Codes are stable across versions; `message` text isn't. |
|
|
| `details` | When `hint` and `message` aren't enough. Often contains the offending value, key, or row. |
|
|
| `message` | As the human summary. Useful in UI strings, less useful for debugging. |
|
|
|
|
A full list of PostgREST error codes is in the [Error Codes reference](/guides/api/rest/postgrest-error-codes).
|
|
|
|
## Branch on `error.code`, not `error.message`
|
|
|
|
`error.code` is more reliable than `error.message` for programmatic branching: messages change between Postgres and PostgREST versions, but codes are stable.
|
|
|
|
```ts
|
|
const { data, error } = await supabase.from('users').select()
|
|
if (error) {
|
|
console.error(error)
|
|
if (error.code === '42501') {
|
|
// Permission denied. error.hint usually contains the GRANT to run.
|
|
}
|
|
return
|
|
}
|
|
```
|
|
|
|
## Errors from Auth, Storage, and Edge Functions
|
|
|
|
The same rule applies across the SDK — log the whole error object — but the shape differs by client.
|
|
|
|
### Auth
|
|
|
|
`AuthError` exposes `error.code` (e.g. `'invalid_credentials'`, `'email_not_confirmed'`) and `error.status`. Branch on `code`; log the whole thing.
|
|
|
|
```ts
|
|
const { data, error } = await supabase.auth.signInWithPassword({
|
|
email: 'example@email.com',
|
|
password: 'example-password',
|
|
})
|
|
if (error) {
|
|
console.error(error)
|
|
return
|
|
}
|
|
```
|
|
|
|
### Storage
|
|
|
|
`StorageError` exposes `error.statusCode` (HTTP status as a string) and a structured `error` name (e.g. `'Duplicate'`, `'NotFound'`).
|
|
|
|
```ts
|
|
const { data, error } = await supabase.storage
|
|
.from('avatars')
|
|
.upload('public/avatar1.png', avatarFile)
|
|
if (error) {
|
|
console.error(error)
|
|
return
|
|
}
|
|
```
|
|
|
|
### Edge Functions
|
|
|
|
Functions errors arrive as one of three subclasses. Narrow with `instanceof`; for `FunctionsHttpError`, parse the body to get the function's own error payload.
|
|
|
|
```ts
|
|
import { FunctionsFetchError, FunctionsHttpError, FunctionsRelayError } from '@supabase/supabase-js'
|
|
|
|
const { data, error } = await supabase.functions.invoke('hello')
|
|
if (error instanceof FunctionsHttpError) {
|
|
console.error('Function error', await error.context.json())
|
|
} else if (error) {
|
|
console.error(error)
|
|
}
|
|
```
|
|
|
|
### Realtime
|
|
|
|
The `subscribe()` callback receives a `status` and, on failure, an `err` argument. Log the whole `err` — its `cause` often holds the underlying reason.
|
|
|
|
```ts
|
|
supabase.channel('room1').subscribe((status, err) => {
|
|
if (status === 'CHANNEL_ERROR' || status === 'TIMED_OUT') {
|
|
console.error(status, err)
|
|
}
|
|
})
|
|
```
|
|
|
|
## Related
|
|
|
|
- [PostgREST Error Codes](/guides/api/rest/postgrest-error-codes)
|
|
- [Automatic retries with `supabase-js`](/guides/api/automatic-retries-in-supabase-js)
|
|
- [Securing your API](/guides/api/securing-your-api)
|