symfony/translation · error · InvalidArgumentException
The translation provider DSN must contain a host (use…
Error message
The translation provider DSN must contain a host (use "default" by default).
What it means
Dsn requires a host component after scheme validation. Without a host the factory cannot target the provider API, so InvalidArgumentException is thrown; the message hints that "default" may be used where a provider accepts it.
Solutions
- Add the provider's host to the DSN: 'scheme://key@host'.
- Use 'default' as the host when the provider factory supports it (e.g. 'loco://KEY@default').
- Check the env var/config for a truncated value (commonly missing after '@').
- Look up the correct host in the provider factory's docs or tests for the scheme you use.
Example fix
// before
new Dsn('loco://API_KEY@');
// after
new Dsn('loco://API_KEY@default'); Defensive patterns
Strategy: validation
Validate before calling
$params = parse_url($dsn);
if (!isset($params['host']) || '' === $params['host']) {
throw new \InvalidArgumentException('DSN must include a host (use "default" if supported)');
} Try / catch
try {
$dsn = new Dsn($rawDsn);
} catch (\InvalidArgumentException $e) {
// append the provider host or 'default' before retrying
} Prevention
- Include the host in every DSN, even when using the 'default' placeholder.
- Check for truncated env vars — content is often lost right after '@'.
- Copy the DSN template from the provider factory's documentation verbatim.
When it happens
Trigger: new Dsn('loco://key@') or DSNs ending right after credentials with no host, e.g. 'scheme://user:pass@' or a truncated DSN in an env var.
Common situations: Templated DSN where the host variable was empty, cutting the string at '@' when copying credentials, or writing 'loco://key' assuming a default host exists for every provider.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- The translation provider DSN is invalid.
- The translation provider DSN must contain a scheme.
- User is not set.
- Password is not set.
- Missing required option
AI-assisted analysis of symfony/translation@ae9e8a51bc (2026-09-15).
Data as JSON: /api/errors/89736976fdb23321.
Report an issue: GitHub.
Appendix: source
Thrown at Provider/Dsn.php:46
private ?string $path;
private array $options = [];
private string $originalDsn;
public function __construct(#[\SensitiveParameter] string $dsn)
{
$this->originalDsn = $dsn;
if (false === $params = parse_url($dsn)) {
throw new InvalidArgumentException('The translation provider DSN is invalid.');
}
if (!isset($params['scheme'])) {
throw new InvalidArgumentException('The translation provider DSN must contain a scheme.');
}
$this->scheme = $params['scheme'];
if (!isset($params['host'])) {
throw new InvalidArgumentException('The translation provider DSN must contain a host (use "default" by default).');
}
$this->host = $params['host'];
$this->user = '' !== ($params['user'] ?? '') ? rawurldecode($params['user']) : null;
$this->password = '' !== ($params['pass'] ?? '') ? rawurldecode($params['pass']) : null;
$this->port = $params['port'] ?? null;
$this->path = $params['path'] ?? null;
parse_str($params['query'] ?? '', $this->options);
}
public function getScheme(): string
{
return $this->scheme;
}
public function getHost(): string
{
return $this->host;View on GitHub (pinned to ae9e8a51bc)