Skip to content

[Console] Improve #[Argument]/#[Option] exception messages #60447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
from

Conversation

kbond
Copy link
Member

@kbond kbond commented May 17, 2025

Q A
Branch? 7.3
Bug fix? no
New feature? no
Deprecations? no
Issues Fix #60412
License MIT

Includes the class/method in #[Argument]/#[Option] exception messages.

Example

The option parameter "$a" of "App\Command\SendSalesReportsCommand::__invoke()" must declare a default value.

The exception messages now include the method:

> The option parameter "$a" of "App\Command\SendSalesReportsCommand::__invoke()" must declare a default value.
@kbond kbond requested a review from yceruto May 17, 2025 23:41
@kbond kbond requested a review from chalasr as a code owner May 17, 2025 23:41
@carsonbot carsonbot added this to the 7.3 milestone May 17, 2025
@yceruto
Copy link
Member

yceruto commented May 18, 2025

@kbond it seems tests failures are related

@kbond
Copy link
Member Author

kbond commented May 18, 2025

Ak, indeed, I'll get them fixed

@@ -27,6 +27,8 @@

class InvokableCommandTest extends TestCase
{
private const FUNCTION_NAME = 'Symfony\Component\Console\Tests\Command\InvokableCommandTest::Symfony\Component\Console\Tests\Command\{closure}()';
Copy link
Member

@GromNaN GromNaN May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the 2 namespaces? It should be Symfony\Component\Console\Tests\Command\InvokableCommandTest\{closure}()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the code to extract the function name from

if (($function = $parameter->getDeclaringFunction()) instanceof \ReflectionMethod) {
. With closures it's a little wonky I admin - plus it changes in 8.4 to include more context (hence the current failures).

For invokable classes, which most of these new commands will be in practice, the name looks like you expect: App\Command\SendSalesReportsCommand::__invoke()

@OskarStark OskarStark added the ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" label May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Console ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" Status: Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Console] 7.3 Add source filename to #[Option] error messages
6 participants