Skip to content

Commit

Permalink
minor #54367 [DependencyInjection] Update an error message (javieregu…
Browse files Browse the repository at this point in the history
…iluz)

This PR was merged into the 7.1 branch.

Discussion
----------

[DependencyInjection] Update an error message

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | -
| License       | MIT

In a Symfony app I had the following:

```php
#[Autowire('%env(kernel.project_dir)%')] private string $projectDir,
```

This should be instead:

```php
#[Autowire('%kernel.project_dir%')] private string $projectDir,
```

In the console I saw this error message:

<img width="822" alt="" src="https://github.com/symfony/symfony/assets/73419/c0303757-36bd-41ab-9ba1-ef912c9740df">

In my opinion, the error is not perfectly clear. That's why in this PR I propose some changes for your consideration. Thanks!

Commits
-------

156e5ba [DependencyInjection] Update an error message
  • Loading branch information
fabpot committed Mar 22, 2024
2 parents ca70200 + 156e5ba commit 292008b
Showing 1 changed file with 1 addition and 1 deletion.
Expand Up @@ -42,7 +42,7 @@ public function get(string $name): array|bool|string|int|float|\UnitEnum|null
}
}
if (!preg_match('/^(?:[-.\w\\\\]*+:)*+\w*+$/', $env)) {
throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name));
throw new InvalidArgumentException(sprintf('The given env var name "%s" contains invalid characters (allowed characters: letters, digits, hyphens, backslashes and colons).', $name));
}
if ($this->has($name) && null !== ($defaultValue = parent::get($name)) && !\is_string($defaultValue)) {
throw new RuntimeException(sprintf('The default value of an env() parameter must be a string or null, but "%s" given to "%s".', get_debug_type($defaultValue), $name));
Expand Down

0 comments on commit 292008b

Please sign in to comment.