# Missing Variables

> Before every deploy, Potions checks config/runtime.exs for the environment variables your app requires, and stops in seconds when one is missing.

A Phoenix app that boots without a variable it needs fails at the very end of a deploy, after the build. Potions checks for that before the build starts, so a missing `STRIPE_SECRET_KEY` costs you seconds, not a full build.

## What the check reads

Before each deploy, Potions reads `config/runtime.exs` from the exact commit being deployed (in your root directory, for a monorepo app). It looks at the code that always runs in your app's environment, usually the `if config_env() == :prod do` block, and finds the variables it can't run without:

- `System.fetch_env!("NAME")`
- `System.get_env("NAME") || raise "..."`
- Dotenvy's `env!("NAME")` and `env!("NAME", :string)`

A variable counts as missing when your app doesn't have it and Potions doesn't set it for you. A stock Phoenix app never trips the check: Potions creates `DATABASE_URL` (or `DATABASE_PATH`) and `SECRET_KEY_BASE` for every app.

## What it ignores

The check only blocks on what it's sure about. It ignores:

- Variables with a default, such as `System.get_env("POOL_SIZE") || "10"` or `System.get_env("PORT", "4000")`.
- Code that only runs sometimes: other environments, `if` conditions on anything but `config_env()`, `case`, `cond` and functions.
- Variable names built at runtime.
- Variables the file sets itself with `System.put_env`, for example from a mounted secrets file. If a `System.put_env` call sets names Potions can't read, the check blocks on nothing in that file.
- Other config files. `prod.exs` is read at compile time, so problems there fail the build loudly anyway.

If Potions can't read the file (there isn't one, it's over 256 KB, it doesn't parse, or GitHub doesn't answer), the deploy goes ahead as before, with a note in the log.

## When something is missing

Pushes and dashboard deploys stop in seconds with "Missing environment variables" and the names in the log. The failure email links straight to the fix, and so does **Add missing variables** on the Deployments tab.

Agents that deploy through the [API](/docs/api-reference) get the names and the same link before anything is queued, so no deployment is created at all.

## Add the values and deploy

The link opens your app's **Environment** tab with an **Add these variables** card, one row per missing name. Enter the values, choose a kind for each, then:

- **Save** stores them. They apply on the next deploy.
- **Save and deploy** stores them and deploys the commit that was missing them.

The link holds only names and a commit, never a value, and it doesn't log you in: you sign in as usual, and only you can open your app's page. If your agent sent you the link, tell it when you're done and it follows the deploy.
