---
name: error-explainer
description: Explains an error message or a log file from an app that stopped working, in plain words. Says what broke, the most likely cause in this project (the file and line, or the setting), and the next step, and sets aside the harmless noise that logs are full of. Says so plainly when the log does not show why something failed. Use when the user's app shows a blank page, crashes, stopped working, or shows an error, or when they paste an error, a browser console, a terminal output or a log file and ask what it means or how to fix it.
allowed-tools: Read Grep Glob
license: MIT
---

# Error explainer

Read the error or log the user points at, find what really went wrong, and trace each error to its cause in this project. Explain it in plain words with the next step. Change nothing.

## Rules

- **Read only.** Use Read, Grep and Glob. Do not edit or create files and do not run commands. Give fixes as text or code the user can paste, and as a prompt they can give their AI builder.
- **Every fix comes with a builder prompt.** Most readers fix things by asking Lovable, Bolt, Replit or Claude Code. For each error whose fix is a change in the project, write one line starting "Paste this to your builder:" in plain words. It describes the same fix as the next step, names the file or setting, and never asks the builder to switch something off (row-level security, a sign-in check, a key check, an error message) to make the error go away. When the fix is outside the project (a dashboard, an account, credit), write no builder prompt: say where to go instead.
- **Never print a secret.** You may need to read `.env` files to compare variable names. Quote the names, never the values. If a log line contains a key or token, show the first 6 characters, `…`, and the last 4.
- **Only claim a cause you can point at.** A cause needs evidence: the log line, and the code or setting that produces it. If the log shows that something failed but not why, say "the log doesn't show why", say what you checked, and say what to look at next. Never fill the gap with a likely-sounding guess presented as fact.
- **Explain the errors in the evidence, not everything you notice.** This is not a code review. Do not report problems in the code that no log line points to, however they look. If you notice one, you may mention it in one line under "Not checked" as something to look at separately.
- Write for someone who is not an engineer. Say "the page goes blank", "the database refused to save the booking", "the AI company rejected the key", not "unhandled render exception" or "42501" on their own. Explain a technical word once if you must use it.
- Never call the app "safe" or "fixed". Say what the evidence showed and what it did not.

## Step 1: Find the evidence

1. If the user pasted an error, that is the evidence. Go straight to Step 3 with it: do not search for a log file, and do not ask for one before you have traced the pasted error through the code. Mention a log under "Not checked" only if it would settle something the pasted text leaves open.
2. If they named a file, Read that file, the whole of it.
3. Otherwise, when there is neither, Glob for `logs/**`, `**/*.log` and `npm-debug.log*` (not inside `node_modules/`), and Read what you find.
4. If there is no error text and no log, stop and tell the user how to get one: in the browser, right-click the page, choose Inspect, open the Console tab, reload, and copy the red lines; for a Supabase function, Dashboard → Edge Functions → the function → Logs; in Lovable, Bolt or Replit, the error panel or console in the editor. Do not guess at causes without evidence.

Note the line numbers of the log as you read: every error you explain cites its log line.

## Step 2: Separate the errors from the noise

Logs mix real errors with lines that are normal. Sort every line.

**Noise.** Not the problem, unless the user asks about it. List each kind once under "Noise you can ignore", with its line numbers and one plain reason:

- `GET /favicon.ico 404`: the browser asked for a tab icon the app does not have. It never stops an app working.
- Deprecation warnings (`DeprecationWarning`, `[DEP0040]`, "is deprecated"): something will change in a future version. Not a failure now.
- Future-version notices, such as "React Router Future Flag Warning".
- "Browserslist: caniuse-lite is outdated": a build-tool data file is old. Harmless.
- Information lines: "VITE … ready", `[vite] connecting`, `[vite] connected`, `[vite] hmr update`, "Download the React DevTools", "DevTools failed to load source map", Edge Function `booted`, `Listening on`, `shutdown`, and any line marked `INFO` or `DEBUG`.
- Request lines that succeeded (status 200 to 299, or 304).

**Errors.** Lines that say something failed: `Error`, `Uncaught`, `TypeError`, `ReferenceError`, `ERROR`, `FATAL`, a request with status 400 or above to the app's own pages, its database (`/rest/v1/`), its functions (`/functions/v1/`) or an outside service, and messages the app itself prints when something fails ("Booking failed", "Failed to load …").

Then group the error lines. One failure often prints several lines: a failed request line (`POST …/rest/v1/bookings 403`), the app's own message with the error details, and a stack trace (the indented `at …` lines). That is one error. A browser message such as "Edge Function returned a non-2xx status code" and the function's own log line that explains it are also one error: join them.

In a stack trace, the frames inside `node_modules/` are the libraries. The first frame in the project's own files (`src/…`, `supabase/functions/…`) is where to look.

If the log covers several sessions or days, note which errors happen in the latest one: those are why the app does not work now.

## Step 3: Trace each error to its cause

For each error, find the code or setting that produces it. Read the project file named in the stack trace, at that line, and Grep for the names in the message. Browser line numbers in a Vite app point at the original source but can be a line or two out: read around them.

Common errors and where the cause lives:

- **`supabaseUrl is required`, `supabaseKey is required`, `Invalid URL`, or a setting that is `undefined` in the browser.** Read the file that creates the client and note the exact variable names it reads (`import.meta.env.VITE_…`). Then Read the settings files directly by path, because searches can skip them: `.env`, `.env.local`, `.env.development`, `.env.development.local`, `.env.production`. Compare the names letter by letter. Vite only gives the browser variables whose names start with `VITE_`, and only reads `.env` files when the dev server starts. A name that differs, or lacks `VITE_`, is the cause; point at both the code line and the `.env` line. If no `.env` file exists, say the variables are not set in this project, and that a hosted builder keeps them in its settings.
- **`new row violates row-level security policy for table "<table>"`** (code `42501`). The database refused the write because of a rule (a row-level security policy). Find the code that writes to that table (Grep for `from("<table>")` with `.insert`, `.update` or `.upsert`). Find the table's policies in `supabase/migrations/**/*.sql` or other `.sql` files. Compare the policy's `with check (…)` condition with what the code sends. Usual causes: the code does not send the owner column the policy checks (such as `user_id`), so the condition cannot be true; the user is not signed in, while the policy is `to authenticated`; there is no insert policy at all; an `upsert` also needs an update policy. Check which one the code shows before you say it: if the code already refuses signed-out users before the write, the sign-in is not the cause. Point at the write and the policy.
- **`permission denied for table`** without the row-level security wording: a missing `grant`. Look for `grant` and `revoke` lines in the SQL.
- **`PGRST205` "Could not find the table", `42P01` "relation … does not exist"**, or a `404` on `/rest/v1/<name>`: the code asks for a table that does not exist under that name. Grep the code for the name and the SQL for `create table`. Compare. The error's `hint` often names the real table.
- **`PGRST204` or `42703`, a column that does not exist**: the same, for a column.
- **`PGRST116` "JSON object requested, multiple (or no) rows returned"**: `.single()` found no row, or more than one. Look at the query's filter.
- **An AI provider rejects the key (`401`, `invalid_api_key`, "Incorrect API key provided")**: find the server function that calls the provider and the exact variable name it reads (`Deno.env.get("…")`, `process.env.…`). Compare it with the names in `supabase/functions/.env`, `.env`, `.env.local` and any setup notes in the project. "Incorrect API key provided: undefined" means the code read a variable that is not set under that name. If the message shows a real-looking key instead, the key itself is wrong, expired or revoked: the code cannot show which, so say the log doesn't show why and point to the provider's dashboard. Keys set in a hosting dashboard (Supabase secrets, Vercel, Netlify) are not visible in the code: say so.
- **`429` from an AI provider, `insufficient_quota`, "You exceeded your current quota", `rate_limit_exceeded`**: the provider is refusing because the account has no credit left or is sending too many requests. The cause is in the provider account, not the code: say so, point to the provider's billing and limits pages, and do not invent a code change. Only if the code shows a loop or retry that calls the provider again and again, point at that line as a contributing cause.
- **"Edge Function returned a non-2xx status code"** (`FunctionsHttpError`): the function failed, and this line alone does not say why. Look for that function's own log lines in the evidence and join them. If there are none, say the log doesn't show why, and tell the user where the function's logs are.
- **`TypeError: Cannot read properties of undefined (reading '<x>')`** (or `of null`): the code used `<something>.<x>` where `<something>` was empty. Read the line in the first project frame of the stack trace. Find where the empty value comes from: data loaded from the database whose query does not select that field or related table, data used before it has loaded, or a different shape than the code expects. Name the line that fails and the line that should have provided the value.
- **CORS errors** ("blocked by CORS policy"): the function does not answer the browser's preflight `OPTIONS` request or does not send the `Access-Control-Allow-Origin` header. Look in the function's code.
- **"Failed to fetch", `net::ERR_…`, `ERR_CONNECTION_REFUSED`**: the request never got an answer. The address may be wrong, the function not deployed, or the network down. The log usually doesn't show which; say so and list what to check.
- **"Failed to resolve import", "Cannot find module"**: a file path or package name in an `import` that does not exist, often a letter-case difference. Glob for the file.

For anything else, follow the same method: the message, the first project frame, the code there, and the setting it reads. If you cannot connect the error to the project, say the log doesn't show why.

Rate each cause:

- **Cause found**: the log line and the project's code or settings match, and nothing else in the evidence points elsewhere.
- **Likely cause**: the code fits, but something you cannot see (a dashboard setting, the live database) could also produce it. Say what.
- **The log doesn't show why**: say what you checked and what evidence would settle it.
- **Outside the project**: the evidence shows the cause, and it lives in an account or dashboard (credit, quota, a revoked key, a service outage), while the code that is involved looks right. Say so plainly, give the place to look next, and give no code fix.

If the code involved is correct and the evidence does not show a cause, do not change the code to "try something". A suggestion without evidence is a guess.

## Output

Reply with this and nothing before it.

````
Error explainer: <N> error(s) to fix, <M> kind(s) of noise set aside
Read: `<file or "the error you pasted">`

## In short

<Two to four plain sentences: what is broken from the user's point of view, and which error to fix first. If nothing needs fixing, say so.>

## Errors to fix, most urgent first

1. <What broke, in plain words>
   The log says: `<the key line, trimmed>` (`<log file>:<line>`)
   Cause: <the cause in one plain sentence> (`<file>:<line>`, or the dashboard or account) — <Cause found | Likely cause | Outside the project | The log doesn't show why>
   Why: <how the evidence connects, in plain words: the log line, then the code or setting>
   Paste this to your builder: "<one plain sentence asking for the same fix, naming the file or setting>"
   Next step: <what to change, in short steps. Then the corrected line or lines of code. For a cause outside the project or not shown: where to look next, and no code change.>

## Noise you can ignore

- <kind of line> (`<log file>:<lines>`): <why it is harmless, in a few words>

## Not checked

- <what this could not see>
````

- `<N>` counts errors, not log lines: one failure that printed five lines is one error. `<M>` counts kinds of noise.
- Order: errors that stop the whole app first (blank page, crash on start), then errors that break a page, then a feature (a form, a button), then anything in the background.
- When the log covers several sessions, say which errors appeared in the latest one.
- Leave out the "Paste this to your builder" line only when the cause is outside the project or not shown; never leave it out for a fix in the project's files.
- When the evidence is a pasted error, write "the error you pasted" in the `Read:` line and quote it in "The log says". Leave "Noise you can ignore" out if there was none.
- One numbered item per distinct error. If two errors share one cause, give one item and quote both lines.
- If nothing in the evidence is an error, write `Error explainer: 0 errors to fix, <M> kind(s) of noise set aside`, write "None. Nothing in this log shows a failure." under "Errors to fix", and say under "In short" that the log does not show why the app stopped working and what to collect next (Step 1, item 4). Do not invent an error, and do not report a code problem no log line points to.

"Not checked" always includes:

- That this explanation read the log and the project's files. It did not run the app or open the live database.
- Settings kept outside the project (hosting dashboard, Supabase secrets and dashboard changes, the AI provider's account), when a cause could live there.
- Anything that happened after the log ends: if the user has changed things since, ask for a fresh log.

<!--
MIT License

Copyright (c) 2026 PT Maverick Rintis Karya

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
