-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] rename exception interface #13798
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
Conversation
Q | A |
---|---|
Bug fix? | no |
New feature? | no |
BC breaks? | no |
Deprecations? | yes |
Tests pass? | yes |
Fixed tickets | - |
License | MIT |
Doc PR | - |
This empty interface looks oddly. Maybe it makes sense to add base class of Serializer exceptions for 3.0 and remove interface completely? I think extending SPL exceptions like |
@unkind the SPL exception give semantic meaning (logic vs runtime). so they are not useless IMO. |
I don't say they are useless, I don't like idea of having this structure: |
The point is domain separation - each domain should have its own domain-specific exceptions, so that you can layer domains and still know which layer is at fault. That's also the reason for wrapping exceptions in domain specific exceptions (thus ->getPrevious() on the base Exception class) |
Right, but why do you need SPL exceptions then? Any case when you would try to catch generic My point is that empty interface indicates a problem. I know concept of a marker interface, but it's different case IMO. |
👍 for this change. |
As explained by @nicolas-grekas, use cases are:
Think about a generic Logger, not aware of libraries used in the project, and logging only runtime exceptions (ignoring logic exceptions). Thanks to If Btw, this is done the same way in other Symfony components: https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Validator/Exception/RuntimeException.php |
I can understand catching just But seriously, I fail to find any case for |
@unkind To be able to catch So it's better leverage the SPL and extends the more precise exceptions such as |
OK, I have to clarify my opinion: I don't like idea of inheriting try {
return $serializer->serialize($foo);
} catch (\Exception $e) {
$this->logger->error('We are screwed and I have no idea why', ['exception' => $e]);
return '';
} but usually I'd prefer to fail by default, because ignoring error can lead serious bugs in the future (http://en.wikipedia.org/wiki/Fail-fast). Well, you can inherit them, but thanks to they are runtime, you don't have to. For example, But for bad incoming data you have to throw regular (non-runtime) exception which would extend |
I'm not sure I understand where you want to go @unkind. Anyway, this discussion is not related to this PR. Here I only want to fix a class that does not respect a naming convention applied everywhere otherwise (Interface suffix for interfaces). |
* | ||
* @author Johannes M. Schmitt <schmittjoh@gmail.com> | ||
*/ | ||
interface ExceptionInterface extends Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be the other way around ? Exception
extending the ExceptionInterface
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope: this way allows the best forward/backward compatibility
👍 |
Before merging, @nicolas-grekas Can you add a note in the CHANGELOG of the component and a note in the UPGRADE file for 3.0? |
f09bdab
to
c6bf1de
Compare
Notes added (is it enough?) |
Looks good to me. |
👍 |
Thank you @nicolas-grekas. |
This PR was merged into the 2.7 branch. Discussion ---------- [Serializer] rename exception interface | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- c6bf1de [Serializer] rename exception interface
…grekas) This PR was merged into the 2.7 branch. Discussion ---------- [Serializer] rename exception interface | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- c6bf1de [Serializer] rename exception interface