Skip to content
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

BUGFIX: PR 4425 FusionGlobals followup / fix #4527

Merged

Conversation

mhsdesign
Copy link
Member

@mhsdesign mhsdesign commented Sep 17, 2023

This is a little followup to #4425

This fixes a bug with the error handling when overriding a fusion global variable.

Also we add a possibility to override the exception handler in the Runtime.

It configures this runtime to override the default exception handler configured in the settings
or via Fusion's @exceptionHandler.

In combination with the throwing handler (ThrowingHandler) this can be used to rethrow all exceptions.
This is helpfully for renderings in CLI context or testing.

$runtime->overrideExceptionHandler(new ThrowingHandler());

Upgrade instructions

Review instructions

Best reviewed commit by commit ;)

In case one overrides a fusion global an error should occur. Currently there is an error in the error handling:

Fatal error: Uncaught TypeError:
Neos\Fusion\Core\ExceptionHandlers\AbstractRenderingExceptionHandler::exceptionDisablesCache(): Argument # 2 ($exception) must be of type Exception, null given, called in /Neos/Neos.Fusion/Classes/Core/ExceptionHandlers/AbstractRenderingExceptionHandler.php on line 69.

This was caused by using the RuntimeException wrongly

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

We don't want first level support for this!
Configures this runtime to override the default exception handler configured in the settings
or via Fusion's @ExceptionHandler {@see AbstractRenderingExceptionHandler}.

In combination with the throwing handler {@see ThrowingHandler} this can be used to rethrow all exceptions.
This is helpfully for renderings in CLI context or testing.
The Fusion RuntimeException declared a few optional parameters, which are actually not optional and code will fail if they return null.

In the case for the Exceptions like 'Overriding Fusion global variable "request" via @context is not allowed.' - One should rather use the generic Fusion Exception.
Copy link
Member

@bwaidelich bwaidelich left a comment

Choose a reason for hiding this comment

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

+1 by reading

Comment on lines +930 to +939
/**
* Configures this runtime to override the default exception handler configured in the settings
* or via Fusion's \@exceptionHandler {@see AbstractRenderingExceptionHandler}.
*
* In combination with the throwing handler {@see ThrowingHandler} this can be used to rethrow all exceptions.
* This is helpfully for renderings in CLI context or testing.
*/
public function overrideExceptionHandler(AbstractRenderingExceptionHandler $exceptionHandler): void
{
$this->overriddenExceptionHandler = $exceptionHandler;
Copy link
Member Author

Choose a reason for hiding this comment

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

This might need to be discussed - but i like this idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mficzel are you fine with this idea as well?

Copy link
Member

Choose a reason for hiding this comment

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

Fine yes but i wonder why it is not mentioned in the description.

Copy link
Member Author

Choose a reason for hiding this comment

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

added ;) lets merge? ^^

* @param null $fusionPath
*/
public function __construct($message = '', $code = 0, \Exception $previous = null, $fusionPath = null)
public function __construct(string $message, int $code, \Exception $previous, string $fusionPath)
Copy link
Member

Choose a reason for hiding this comment

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

Is the api change to make $fusionPath non optional really intended. It makes sense but it is a little breaky.

Copy link
Member

Choose a reason for hiding this comment

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

However i could not find any code that actually is harmed by this even in the oldest projects i found. So it is probably safe

Copy link
Member Author

@mhsdesign mhsdesign Sep 19, 2023

Choose a reason for hiding this comment

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

au contraire, not changing it will allow the fusion path at first to be empty and result in an obscure null error as we trust this value at other places to be non null -> thats why i changed it to avoid future pitfalls of us fusion runtime developers, and make it crystal clear that it is not nullable!

And i also consider the runtime exception to be internal api ...

Copy link
Member Author

Choose a reason for hiding this comment

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

THANK you for making sure i dont break stuff again btw ;) ❤️

@mhsdesign mhsdesign requested a review from mficzel September 20, 2023 09:47
Copy link
Member

@mficzel mficzel left a comment

Choose a reason for hiding this comment

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

Fine by reading. Makes sense now thanks for the explanation.

@mhsdesign mhsdesign merged commit cbf47bf into 9.0 Sep 20, 2023
8 checks passed
@mhsdesign mhsdesign deleted the feature/customDefaultContextVariablesFusionRuntime-followup branch September 20, 2023 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants