# Troubleshooting functions
Source: https://sovaria.in/docs/troubleshooting-functions

Calls refused (401, 403, 404, 409, 429), errors and timeouts inside your code, outbound requests blocked, secrets not visible, and triggers that keep failing.

## 401, 403, 404 or 409 when calling a function

- **Cause:** `401`: the function needs a signed-in caller. `403`: only the service key may call it, or the browser origin isn't allowed. `404`: no function with that name in this environment. `409`: it was saved but never deployed.
- **Check:** The function's caller setting (Functions › your function › Settings) and which environment's URL you call.
- **Fix:** Sign the user in, loosen the caller setting, call the right environment, or deploy ([Deploying and running functions](https://sovaria.in/docs/functions-deploy-and-run)).
- **Verify:** The call returns `200` with `X-Sovaria-Invocation-Id`.

## 429 when calling a function

- **Cause:** The function's rate limit, or the organization's concurrent-run limit (`PLAN_LIMIT_REACHED`, `fn.concurrency`), was reached.
- **Check:** The error code and `Retry-After`; Functions › Events & logs for how many runs overlap.
- **Fix:** Retry after `Retry-After`; shorten runs; move long work to asynchronous calls or a queue; upgrade for more concurrency ([Function memory, timeout and limits](https://sovaria.in/docs/functions-limits)).
- **Verify:** Calls succeed at your normal traffic.

## 422 FUNCTION_FAILED, 5xx, or runs logged as FAILED or TIMEOUT

- **Cause:** `422 FUNCTION_FAILED`: your code raised an error; the message is its first line (the stack trace is only in the logs, never sent to callers). `5xx`: it ran past its timeout or out of memory. Retrying a `422` gives the same error.
- **Check:** Find the run by its `X-Sovaria-Invocation-Id` in Functions › Logs (`sov fn logs <name>`). The error and stack trace are there.
- **Fix:** Fix the error; raise memory or the timeout within your plan (Functions › Memory & timeout); roll back with `sov fn rollback <name>` while you fix it.
- **Verify:** Run it locally with `sov fn serve`, then deploy; new runs are logged as successful.

## Outbound requests from a function fail

- **Cause:** Functions can only reach hosts on their allowed list; others are refused.
- **Check:** The host in the failing request and the function's allowed hosts.
- **Fix:** Add the host (including your own project host if the function calls Sovaria) — within the plan's number of hosts ([Function memory, timeout and limits](https://sovaria.in/docs/functions-limits)).
- **Verify:** The request succeeds on the next run.

## A secret or environment variable is missing or old

- **Cause:** It was set for another environment, or bound under a different name. A changed function secret reaches the next run, and a changed project secret (Settings › Secrets) reaches runs within about a second, without a redeploy.
- **Check:** `sov secrets list <function>` (values are masked) and the environment you call.
- **Fix:** Set it for the environment the function runs in (`sov functions secrets set NAME=… --env <env>`); read it by the exact name.
- **Verify:** Log whether the variable is present (never its value) in a test run.

## A database, auth, storage or schedule trigger keeps failing

- **Cause:** The handler raises an error for some events; failed runs are retried, then kept in the dead-letter queue.
- **Check:** Functions › Events & logs: the trigger's failed runs and the dead-letter queue.
- **Fix:** Fix the handler, make it safe to run twice, then replay the dead letters ([Event triggers](https://sovaria.in/docs/function-triggers)).
- **Verify:** Replayed events succeed and the queue empties.

## Still stuck?

Email [outreach@sovaria.in](mailto:outreach@sovaria.in) with your project URL, the time it happened (with time zone), the `X-Request-ID` response header or the `trace_id` from the error body, and the function name and an invocation id. Never send keys, passwords, tokens or your users' data.
