symfony/translation · error · MissingRequiredOptionException

Missing required option

Error message

Missing required option "%s".

What it means

Thrown by Dsn::getRequiredOption() when a mandatory DSN option (such as the API key in a translation provider DSN) is absent or present but blank. Symfony translation providers use this to fail fast with a clear message instead of an obscure authentication failure later.

Solutions

  1. Add the required option to the DSN, e.g. acfred://API_KEY@default
  2. Verify the environment variable used in the DSN is set and non-empty
  3. Check .env / .env.local for typos in the provider DSN
  4. If calling getRequiredOption yourself, pre-check with getOption($key) and handle absence

Example fix

// before
TRANSLATION_PROVIDER_DSN=acfred://default
// after
TRANSLATION_PROVIDER_DSN=acfred://YOUR_API_KEY@default
Defensive patterns

Strategy: validation

Validate before calling

if ('' === trim((string) $dsn->getOption('key', ''))) {
    throw new \RuntimeException('Provider DSN is missing the API key option.');
}

Try / catch

try {
    $key = $dsn->getRequiredOption('key');
} catch (MissingRequiredOptionException $e) {
    // surface a config hint to the user
}

Prevention

When it happens

Trigger: Calling getRequiredOption($key) on a Dsn object whose options array does not contain $key, or contains it with a value that trims to an empty string.

Common situations: Missing parts of a TRANSLATION_PROVIDER_DSN (e.g. 'acfred://default' without a key), empty environment variable interpolated into the DSN, or a DSN built programmatically with an options array lacking the required key.

Understand the failure class

Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.

Related errors


AI-assisted analysis of symfony/translation@ae9e8a51bc (2026-09-15). Data as JSON: /api/errors/e4bf710183c5e56c. Report an issue: GitHub.

Appendix: source

Thrown at Provider/Dsn.php:90

    public function getPassword(): ?string
    {
        return $this->password;
    }

    public function getPort(?int $default = null): ?int
    {
        return $this->port ?? $default;
    }

    public function getOption(string $key, mixed $default = null): mixed
    {
        return $this->options[$key] ?? $default;
    }

    public function getRequiredOption(string $key): mixed
    {
        if (!\array_key_exists($key, $this->options) || '' === trim($this->options[$key])) {
            throw new MissingRequiredOptionException($key);
        }

        return $this->options[$key];
    }

    public function getOptions(): array
    {
        return $this->options;
    }

    public function getPath(): ?string
    {
        return $this->path;
    }

    public function getOriginalDsn(): string
    {
        return $this->originalDsn;

View on GitHub (pinned to ae9e8a51bc)