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

Refactored ExceptionHandler: separated logging and rendering #18088

Merged
merged 7 commits into from Sep 26, 2020

Conversation

ethernidee
Copy link
Contributor

Summary of Changes

Refactored ExceptionHandler class (previously JErrorPage): separated logging and rendering, added helper methods, replaced old class names (JXxx) with namespaced ones.
Now if ExceptionHandler::render() is called manually from anywhere, no logging is performed. If ExceptionHandler::handleException() is called, both logging and rendering is performed.

Testing Instructions

Enter non-existing url in browser to trigger 404 page.

Expected result

Default template error page should be displayed, as usual.

Documentation Changes Required

No changes.

@wilsonge
Copy link
Contributor

I get there's an element of single responsibility here - but is there a practical reason for breaking this up?

@ethernidee
Copy link
Contributor Author

Yes. The separation allows to render default error page from plugins without logging. My clients were using custom loggers on almost all projects.

  • A few minor improvements, like Joomla 4.0 class names, better readability, better cleaning of buffered output.

Copy link
Contributor

@mbabker mbabker left a comment

Choose a reason for hiding this comment

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

Seems fair to me

@mbabker mbabker added this to the Joomla 3.9.0 milestone Dec 11, 2017
@ghost ghost added the J3 Issue label Apr 5, 2019
@ghost ghost removed the J3 Issue label Apr 19, 2019
@SharkyKZ
Copy link
Contributor

@ethernidee Are you still around? Can you fix the conflict please?

@ethernidee
Copy link
Contributor Author

@ethernidee Are you still around? Can you fix the conflict please?
Done!

// Clear buffered output at all levels in non-test mode
$callerFunction = static::getCallerFunctionName();

if ($callerFunction === false || !preg_match('~\Atest[A-Z]~', $callerFunction))
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of checking for test here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cleaning buffered output during unit-testing makes tests fail, because they rely on all output. In production mode everything outputed before error must be discarded.

Copy link
Contributor

Choose a reason for hiding this comment

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

This wasn't an issue before? I don't think it's right hardcoding a function name here. And what if you have a testSomething() function in production code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I remember correctly, it was an an issue, because only single level of buffering was discarded.
if (ob_get_level) {ob_get_clean()}.

But when exception is raised, there can be multiple level of buffering, thus I clean them all. Because tests began to fail, I had to add some check for test mode. Do you have any other ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I'm dumb with tests. Maybe someone more familiar can comment. @Hackwar @HLeithner ?

Adapted file prolog to Joomla style according to reviewer recommendations
@zero-24 zero-24 modified the milestones: Joomla 3.10.0, Joomla! 3.9.15 Dec 19, 2019
@ghost
Copy link

ghost commented Jan 12, 2020

What is still needed to close this pull ?

@zero-24 zero-24 changed the base branch from staging to 3.10-dev September 25, 2020 06:12
@zero-24
Copy link
Contributor

zero-24 commented Sep 26, 2020

Drone is happy now so whatever was there in the past that is now fixed and that extra code is not needed. Tests would be great :)

@particthistle
Copy link
Member

particthistle commented Sep 26, 2020

Applying patch has no effect on the 404.

Note: Check you have a Joomla .htaccess file in correctly first otherwise you'll be looking at a server level error message instead!

Test on 3.9.21 - Baseline of expectations

Shows the 3.9 Joomla error page.
image

Before test

Shows new error page in 3.10 that is contained in the template
Protostar:
image
Template without error.php:
image

After text

Shows the same error page as before the test. Not sure whether some other PR has already done what this PR is trying to achieve?
Protostar:
image

Template without error.php:
image

@particthistle
Copy link
Member

I have tested this item ✅ successfully on cb7c936


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/18088.

@softforge
Copy link
Contributor

I have tested this item ✅ successfully on cb7c936

There is no change to the 404 page with and without patch applied. And I have checked and the redirect plugin logging is still logging 404s


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/18088.

@joomla-cms-bot joomla-cms-bot removed this from the Joomla 3.10.0 milestone Sep 26, 2020
@alikon
Copy link
Contributor

alikon commented Sep 26, 2020

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/18088.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Sep 26, 2020
@zero-24 zero-24 added this to the Joomla 3.10.0 milestone Sep 26, 2020
@zero-24
Copy link
Contributor

zero-24 commented Sep 26, 2020

Thanks 👍

@zero-24
Copy link
Contributor

zero-24 commented Sep 26, 2020

And thanks @ethernidee for you patience

@zero-24 zero-24 merged commit 471ffeb into joomla:3.10-dev Sep 26, 2020
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Sep 26, 2020
@SharkyKZ
Copy link
Contributor

SharkyKZ commented Sep 26, 2020

@zero-24 This should not have been merged as is. Only part of the code you removed was related to tests. Rest of the code is necessary. Otherwise PHP notices appear on the error page.

@zero-24
Copy link
Contributor

zero-24 commented Sep 26, 2020

Ok can you do a PR else i can do one next week.

@SharkyKZ
Copy link
Contributor

Sorry, I missed a word in the comment. It should have said "This should not have been merged". Neither the original code, nor the merged code is fine.

@HLeithner
Copy link
Member

So what did I missed why this is wrong? Can you fix it or at least explain what should be changed? @SharkyKZ

@SharkyKZ
Copy link
Contributor

See comments #18088 (review).

@zero-24
Copy link
Contributor

zero-24 commented Sep 26, 2020

See comments #18088 (review).

I'm sorry I can not follow you. Based on that comment it was about an failing unit test that does not longer fail right?

@SharkyKZ
Copy link
Contributor

No, we do need to clear the buffer. But this is, apparently, causing issues in tests so @ethernidee added a check for function name as a workaround. But it's not reliable as you can easily have functions starting with test in production code.

@zero-24
Copy link
Contributor

zero-24 commented Sep 26, 2020

Yes that check has been removed and the test issues mention does not seem to happen anymore with drone. We have to take into account that this was an 2017er PR with a totally different testing setup :)

@SharkyKZ
Copy link
Contributor

In that case the code you removed should be restored but without preg_match('~\Atest[A-Z]~', $callerFunction) check.

@zero-24
Copy link
Contributor

zero-24 commented Sep 26, 2020

Ok can you do a PR for that?

@zero-24
Copy link
Contributor

zero-24 commented Sep 27, 2020

PR has been done here: #30786 @SharkyKZ

richard67 pushed a commit that referenced this pull request Jan 19, 2021
Pull Request for Issue #18088

Add back the check to clear the buffered output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet