-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
Do not trigger errors when a block doesn't exist anymore #1115
Conversation
sorry I misunderstand your PR ;) |
can you provide tests please! |
you mean create a new unit test for those changes ? I'm not really familiar with that practice but if you guide me I can try |
src/Block/BlockRenderer.php
Outdated
@@ -79,6 +82,10 @@ public function render(BlockContextInterface $blockContext, ?Response $response | |||
), compact('exception')); | |||
} | |||
|
|||
if ($exception instanceof RuntimeError && !empty($exception->getPrevious()) && $exception->getPrevious() instanceof BlockNotFoundException) { |
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.
I don't think this code belongs here. We have ExceptionStrategyManager for that I guess.
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.
Yes this could be here instead https://github.com/sonata-project/SonataBlockBundle/blob/4.x/src/Exception/Strategy/StrategyManager.php#L107-L125
which would rely on https://github.com/sonata-project/SonataBlockBundle/blob/4.x/src/Exception/Strategy/StrategyManager.php#L113-L114
So maybe it's just a blockRenderer/filter to update in BlockBundle or Pagebundle
This can be a functional test (might be better). The current issue for me is to understand the issue you and @eerison are trying to fix.
Because currently I'm like "Why should be have a different treatment for those errors ?" Also, looking at the code (cf #1115 (comment)) it seems like this could be already configured to not throw an exception but render some error message... Also I don't see why it solve sonata-project/SonataPageBundle#1609 and replace https://github.com/sonata-project/SonataPageBundle/pull/1611/files |
Yeah the purpose of changing exception is to avoid throwing an exception for blocks that does not exist anymore (for example a removed service and still present into page block composition - issue 1609 in sonata page) and keep all other runtime errors.
|
Yep! |
Doing a PR to throws BlockNotFoundException instead of \RuntimeException seems fine to me. The main question is about the way we handle BlockNotFoundException. A failing (functional) test would help to understand the why. We have multiple renderer https://github.com/sonata-project/SonataBlockBundle/tree/4.x/src/Exception/Renderer and filter https://github.com/sonata-project/SonataBlockBundle/tree/4.x/src/Exception/Filter ; might be interesting to know which ones are used in PageBundle that would help to understand why an exception is thrown. |
For sonata-project/SonataPageBundle#1609
And the PR sonata-project/SonataPageBundle#1611 just fix and improve the sonata page compose view behavior when some block has been removed (not throw 500 on block list and allow to remove even if the block does not exists anymore). So it's merly related in our discussions with @eerison |
Yes I looked at the code and kinda understand more the issue. But since there is an exceptionManagerStrategy, we can use a different one. So there are multiple way to solve this and we need to precisely decide if it must be fix in SonataPage or SonataBock.
|
I see the idea, I'll think about it. |
Yep, I'm doing exactly this now :) |
to solve the issue related with page (when open the page it's returning internal server error), I just need this line |
|
Yeah, I think this PR should be reduce to just changing some \RuntimeException to BlockNotFoundException |
Fine for me ! I did the rollback commit |
src/Block/BlockServiceManager.php
Outdated
*/ | ||
private function load(string $type): BlockServiceInterface | ||
{ | ||
if (!$this->has($type)) { | ||
throw new \RuntimeException(sprintf('The block service `%s` does not exist', $type)); | ||
throw new BlockNotFoundException(sprintf('The block service `%s` does not exist', $type)); |
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.
A unit test is required hire!
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.
Yeah, I'll try to do it
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.
I added a test, If you have some comments to improve do not hesitate or the test is not well organized
…ead of \RuntimeError
We can catch it directly here: #1117 |
well I can add the try catch here, But the point is: Can I add the catch like this: https://github.com/sonata-project/SonataBlockBundle/blob/4.x/src/Block/BlockRenderer.php#L73-L86 👀 |
it solves, But the info that BlockService doesn't exist will be hidden, as I said above, can we add this https://github.com/sonata-project/SonataBlockBundle/blob/4.x/src/Block/BlockRenderer.php#L73-L86 |
and other thing, if |
I can add log like this 17f93fc But the exceptionManagerStrategy should not be used since it's supposed to return a Response and we won't use it. |
Yeah it is a bit better then do not log anything 😄 But I guess it should not require exception, it should only handle exception and nothing more! |
But well it's requiring in the interface and it'll be too much work for now :/ |
As explained here: #1117 (comment), this PR works fine with the config
Also, by default it's debug only ; so it won't throw any exception in production. So I think this is not a real issue. |
But the page doesn't render the others blocks |
I'm using the same config that you added above and my page is still broken |
Yes but this is not an issue. |
@JeromeEngelnAdeliom Can you update the tests too ? =) |
do you mean if one block fail, my whole page no make sense anymore? I don't get it! |
Yes it can. Let's say you have a block Text "Please subscribe by giving your email on the next line". I can find more and more example. So the current beahvior is understandable ; and if you want a different one you'll be able to use another manager strategy. Imho it require just some doc on SonataPageBundle. |
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.
The fact that the tests failed mean we introduced a regression. To avoid this we need that BlockServiceNotFoundException extends RuntimeException
Well it really depends of each case in my case some pages uses blocks completely independent each other, and if one block fail, make totally sense for me still keep my page showing with others blocks. But if it's not an impediment for sonata page 4 then It's fine |
And because it depends of each case, each developper should be able to decide what to do. |
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.
The PR looks ok to me, but I can't follow all the conversation. I let you decide if this is ready to merge @VincentLanglet
To me, it is. And this works fine for me. Dunno why @eerison doesn't made it work for him. |
Keep the blocks into the page rendering even if some blocks does not exist
Here a proposition to remove exception on render when a block doesn't not exists anymore.
The purpose of changing exception is to avoid throwing an exception for blocks that does not exist anymore (for example a removed service and still present into page block composition - issue sonata-project/SonataPageBundle#1609 in sonata page) and keep all other runtime errors.
To do that I need to identify not found exception.
if BlockNotFoundException is catched just return an empty response
And for other \RuntimeException just keep old behavior
Related to SonataPageBundle issue sonata-project/SonataPageBundle#1609
And PR sonata-project/SonataPageBundle#1611
Changelog