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

Fix EZP-23913: Override legacy fatal error message #1138

Merged
merged 1 commit into from Mar 16, 2015
Merged

Fix EZP-23913: Override legacy fatal error message #1138

merged 1 commit into from Mar 16, 2015

Conversation

thiagocamposviana
Copy link
Contributor

The message "Fatal error: The web server did not finish its request" cannot be overridden in eZ Publish:

https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/private/classes/ezpkernelweb.php#L213

See more at: https://jira.ez.no/browse/EZP-23913

This pull request allows this to be overridden, the developer can now define a error.ini (only in global escope, ie, settings/override/error.ini.append.php) variable like:

[ErrorSettings-kernel]
FatalErrorHandler=CustomFatalErrorHandlerClass::FatalErrorHandlerFunction

@thiagocamposviana
Copy link
Contributor Author

If you see https://github.com/ezsystems/ezpublish-legacy/pull/1138/files?diff=split

You will notice that I just create one if statement that checks for the existence of such variable.

@peterkeung
Copy link
Contributor

No BC break

+1

@brookinsconsulting
Copy link
Contributor

+1 We love this solution!

@lendormi
Copy link

+1

@trolek
Copy link
Contributor

trolek commented Jan 20, 2015

Shouldn't you also examine the setting for is_callable?


[ErrorSettings]
# Allow the default eZ Publish 500 error message to be overridden
# FatalErrorHandler=CustomFatalErrorHandlerClass::FatalErrorHandlerFunction
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing empty line at the end of the file.

@yannickroger
Copy link
Contributor

+1

@crevillo
Copy link
Contributor

just a thought. as long as we already have a dedicate error.ini file, couldn't we move that setting there too?

@yannickroger
Copy link
Contributor

@crevillo sounds like a good idea

@thiagocamposviana
Copy link
Contributor Author

I have updated the code and now it should a setting defined in the error.ini and also check if the method is callable.

echo "<b>Fatal error</b>: The web server did not finish its request<br/>";
if ( ini_get('display_errors') == 1 )
$errorINI = eZINI::instance( 'error.ini' );
if( $errorINI->hasVariable( 'ErrorSettings-kernel', 'FatalErrorHandler' ) && is_callable( $errorINI->variable( 'ErrorSettings-kernel', 'FatalErrorHandler' ) ) )
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: space after the if

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Carlos, I am not sure about what you mean, there is no trailing spaces there.

Copy link
Contributor

Choose a reason for hiding this comment

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

i'm sayin that the line should be like if ( instead of if(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, thanks.

@thiagocamposviana
Copy link
Contributor Author

Updated code, fixed if statement.

@crevillo
Copy link
Contributor

+1. useful thing!.

@yannickroger
Copy link
Contributor

ping @andrerom @bdunogier @lolautruche @glye

@andrerom
Copy link
Contributor

+/-0 this won't work with siteaccess settings, will only be global, because of how early this is registered (it has to be early, so I'm not saying it should be moved).

@thiagocamposviana
Copy link
Contributor Author

@andrerom

Do you think it should be necessary to put a note in the .ini comment? Something like:

# Allow the default eZ Publish 500 error message to be overridden
# Note: this won't work with siteaccess settings, will only be global, because of how early this is registered
# FatalErrorHandler=CustomFatalErrorHandlerClass::FatalErrorHandlerFunction

@andrerom
Copy link
Contributor

Something like that would help a bit.

@thiagocamposviana
Copy link
Contributor Author

I confirmed the limitation and put a note about it.

@thiagocamposviana
Copy link
Contributor Author

I am not sure why CI build failed, the current code shouldn't be executed at all because it will require that the ini variable to be defined and also the class::method exists, also about the code itself, I checked eZExecution and it adds the fatal error handlers like this:

static function addFatalErrorHandler( $handler )
    {
        self::registerShutdownHandler();
        self::$fatalErrorHandlers[] = $handler;
    }

And call them like this:

$handlers = eZExecution::fatalErrorHandlers();
        foreach ( $handlers as $handler )
        {
            if ( is_callable( $handler ) )
                call_user_func( $handler );
            else

                eZDebug::writeError('Could not call fatal error handler, is it a static public function?', __METHOD__ );
        }

So, it should work, as long as I am passing a string and call_user_func accepts strings.

@thiagocamposviana
Copy link
Contributor Author

Checked https://travis-ci.org/ezsystems/ezpublish-legacy/jobs/47844272

The command "php -d date.timezone=$TEST_TIMEZONE tests/runtests.php --dsn "$DB://${DB_USER}@127.0.0.1/$DB_NAME" tests extension/ezoe" exited with 1.

Seems like an unrelated error is affecting the Travis CI build?

@bdunogier
Copy link
Member

+1 with the principle since it is backward compatible. We could even have a default implement in the LegacyBundle ;-)

Nitpick: given that the modified code doesn't use any variable from the laaaarge constructor's scope, you could move this to a protected method. It wouldn't hurt, and would make this step self-contained.

@thiagocamposviana
Copy link
Contributor Author

Hi Bertrand

Do you recommend a name for the method?

@thiagocamposviana
Copy link
Contributor Author

I have updated the code and moved it to its own method.

@bdunogier
Copy link
Member

Do you recommend a name for the method?

registerFatalErrorHandler ?

@thiagocamposviana
Copy link
Contributor Author

I have seem that setupFatalErrorHandler might be a better option because I have seen some code using setup, is this pull request good enough to be merged?

@yannickroger
Copy link
Contributor

How do we handle improvement PR on legacy now ? ping @andrerom @bdunogier

@brookinsconsulting
Copy link
Contributor

We on the 'eZ Publish Pull Request Team' want this feature merged so it can be included in the next 'eZ Publish 5.x Community Build' (which is being driven now by community support). So we are strongly compelled to encourage this legacy improvement PR from mugo.ca to be merged. We can't 👍 enough this PR!

@yannickroger
Copy link
Contributor

So if everybody is still +1, I'll merge it ;)

@peterkeung
Copy link
Contributor

+1 here

@brookinsconsulting
Copy link
Contributor

+1 Yes please and thank you :)

@bdunogier
Copy link
Member

I don't see anything wrong with it. What do you think, @andrerom ?

yannickroger added a commit that referenced this pull request Mar 16, 2015
Fix EZP-23913: Override legacy fatal error message
@yannickroger yannickroger merged commit f3d39ee into ezsystems:master Mar 16, 2015
@yannickroger
Copy link
Contributor

Thanks @thiagocamposviana

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
9 participants