Skip to content

[Console] Add domain exceptions to replace generic exceptions #14894

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

Closed
wants to merge 5 commits into from

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jun 6, 2015

Creates domain specific exception classes for the case where a user type an invalid command name or option name.

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #14873
License MIT
Doc PR N/A

TODO:

  • Replace \InvalidArgumentException by Symfony\Component\Console\Exception\InvalidArgumentException
  • Add Symfony\Component\Console\Exception\ExceptionInterface


[Symfony\Component\Console\Exception\CommandNotDefinedException]
Command "foo" is not define
d.
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'm not sure this is the correct behavior. The line is wrapped, but not the class name, and the rest of the line is filled with spaces.

Copy link
Member

Choose a reason for hiding this comment

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

I think d should be on the same line as define.

@GromNaN GromNaN force-pushed the console-exception branch from 557e52d to bd025a3 Compare June 6, 2015 15:33
@GromNaN GromNaN changed the title [Console] Add CommandNotDefinedException to replace generic exception [Console] Add domain exceptions to replace generic exceptions Jun 6, 2015
@GromNaN GromNaN force-pushed the console-exception branch from bd025a3 to 0077045 Compare June 6, 2015 19:46
@GromNaN
Copy link
Member Author

GromNaN commented Jun 7, 2015

Any idea how to fix this failing test ?
https://travis-ci.org/symfony/symfony/jobs/65716176#L438

 1) Symfony\Component\Console\Tests\ApplicationTest::testFindAlternativeNamespace
 Failed asserting that Array &0 (
    0 => 'foo'
    1 => 'foo1'
    2 => 'foo3'
) is identical to Array &0 (
    0 => 'foo3'
    1 => 'foo1'
    2 => 'foo'
).
 /home/travis/build/symfony/symfony/src/Symfony/Component/Console/Tests/ApplicationTest.php:444

@phansys
Copy link
Contributor

phansys commented Jun 7, 2015

AFAIK, the alternative names was originally ordered with levenshtein(), but I don't know if your issue is related to this.

{
return $this->alternatives;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, check missing new lines at EOFs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@@ -176,7 +176,7 @@ public function testSilentHelp()
}

/**
* @expectedException \InvalidArgumentException
* @expectedException Symfony\Component\Console\Exception\CommandNotDefinedException
Copy link
Member

Choose a reason for hiding this comment

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

Missing leading \ on all @expectedException tags

Copy link
Member

Choose a reason for hiding this comment

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

Can you fix this? We are using a leading \ everywhere else in Symfony for such PHPUnit annotations.

@fabpot
Copy link
Member

fabpot commented Aug 1, 2015

As you are moving exceptions to specific ones, what about doing it for the whole component?

@fabpot
Copy link
Member

fabpot commented Sep 14, 2015

@GromNaN Any news on this one? Can you address the comments?

@GromNaN
Copy link
Member Author

GromNaN commented Sep 22, 2015

OK for moving remaining exception to specific ones. Is it necessary to keep the distinction between InvalidArgumentException and LogicException in classes like Console/Question/Question ?

@fabpot
Copy link
Member

fabpot commented Sep 22, 2015

Yes, I think we need to keep the distinction here (at least to keep BC).

@GromNaN
Copy link
Member Author

GromNaN commented Sep 22, 2015

I'll create Symfony\Component\Console\Exception\InvalidArgumentException and Symfony\Component\Console\Exception\LogicException

And the interface Symfony\Component\Console\Exception\ExceptionInterface

Replace exception thrown by specific exception implementing the
same interface.
@GromNaN
Copy link
Member Author

GromNaN commented Sep 23, 2015

Rebased and made all changes.

I still have this error on HHVM :

1) Symfony\Component\Console\Tests\ApplicationTest::testFindAlternativeNamespace
Failed asserting that Array &0 (
    0 => 'foo'
    1 => 'foo1'
    2 => 'foo3'
) is identical to Array &0 (
    0 => 'foo3'
    1 => 'foo1'
    2 => 'foo'
).

*
* @author Jérôme Tamarelle <jerome@tamarelle.net>
*/
class CommandNotDefinedException extends \InvalidArgumentException implements ExceptionInterface
Copy link
Member

Choose a reason for hiding this comment

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

I would have named it CommandNotFoundException to be more consistent with other exception names in other components.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's close to the RouteNotFoundException from the Routing component. Have you something in mind ?

Copy link
Member

Choose a reason for hiding this comment

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

CommandNotFoundException

@fabpot
Copy link
Member

fabpot commented Sep 24, 2015

I made some minor comments, but I'm 👍 on this change.

ping @symfony/deciders

@@ -38,7 +39,7 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu

// make required
if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) {
throw new \Exception('A value is required.');
throw new LogicException('A value is required.');
Copy link
Member Author

Choose a reason for hiding this comment

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

Here I've replaced the only instance of the basic \Exception by a more precise LogicException.

@dunglas
Copy link
Member

dunglas commented Sep 24, 2015

👍

@fabpot
Copy link
Member

fabpot commented Sep 25, 2015

Thank you @GromNaN.

@xabbuh
Copy link
Member

xabbuh commented Sep 27, 2015

@GromNaN I had a look at the failing tests: #15940

fabpot added a commit that referenced this pull request Sep 27, 2015
…test (xabbuh)

This PR was merged into the 2.8 branch.

Discussion
----------

[Console] don't rely on internal sort implementation om test

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14894
| License       | MIT
| Doc PR        |

PHP does not guarantuee how array elements with the same value will be
sorted when applying `asort()`. Since all namespaces used in the test
produce the same Levenshtein value, we should only check for presence of
these namespaces instead of comparing the exact order.

Commits
-------

3011fa0 don't rely on internal sort implementation in test
@fabpot fabpot mentioned this pull request Nov 16, 2015
@GromNaN GromNaN deleted the console-exception branch November 16, 2015 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants