-
Notifications
You must be signed in to change notification settings - Fork 175
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
[Core: Module] Handle 500 errors properly #4163
Conversation
That explanation doesn't make sense.. if it doesn't have catches for other exception types they keep propagating, they don't get handled by the wrong handler. try {
throw new Exception("Test");
} catch (BadFunctionCallException $e) { /* A random more specific exception type from SPL */
print "I caught something";
}
print "I am here"; Results in: $ php test.php
PHP Fatal error: Uncaught Exception: Test in /Users/driusan/Code/Loris/test.php:4
Stack trace:
#0 {main}
thrown in /Users/driusan/Code/Loris/test.php on line 4
Fatal error: Uncaught Exception: Test in /Users/driusan/Code/Loris/test.php:4
Stack trace:
#0 {main}
thrown in /Users/driusan/Code/Loris/test.php on line 4 (But it's still an improvement to handle more types, so there's no reason to block it just because the explanation doesn't make sense..) |
php/libraries/Module.class.inc
Outdated
@@ -265,6 +271,7 @@ class Module extends \LORIS\Router\PrefixRouter implements RequestHandlerInterfa | |||
); | |||
} | |||
} catch (\NotFound $e) { | |||
error_log("IN the NotFound 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.
debug statement
php/libraries/Module.class.inc
Outdated
); | ||
} catch (\ConfigurationException $e) { | ||
error_log($e); | ||
error_log(self::CONFIGURATION_ERROR); |
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.
there's no reason to put the message for the users in the error log, you've already logged the exception.
@@ -1,6 +1,4 @@ | |||
<div class="container"> | |||
{foreach from=$error_message item=message} | |||
<h2>{$message}</h2> | |||
{/foreach} |
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.
This shouldn't be changed from an array to a scalar, that will break any other places that use 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.
The issue wasn't so much of array/scalar but that it's inconsistent with
Line 50 in 15c0a27
$tpl_data = array( |
message
instead of error_message
).
Do you prefer to change the Error
class to use error_message
or should the other calling code across LORIS be changed?
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 actually know how many calling places there are, but wouldn't it be easier to change that to 'message' => [$message]
instead of trying to hunt down the other ones?
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.
If you mean change the Error.php
code, then I would need to change the 403
and 404
templates as well as their calling code instead; they use scalars instead of arrays in their templates (in contrast to 500
).
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 have a preference but they need to be standardized one way or another if they are going to use src/Http/Error.php
.
php/libraries/Module.class.inc
Outdated
@@ -277,8 +284,75 @@ class Module extends \LORIS\Router\PrefixRouter implements RequestHandlerInterfa | |||
) | |||
) | |||
); | |||
/* Catch more specific errors that may be thrown in the codebase. | |||
* Without handling these exceptions explicitly, LORIS will display | |||
* a 404 error and swallow the exception, hindering debugging efforts. |
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 like this first paragraph because that's not actually how PHP handles exceptions.
(The second paragraph is fine but there's no reason to have the word "NOTE" at the front.. it's just a comment.)
@ridz1208 This is the PR we were talking about |
@driusan please re-review |
Brief summary of changes
Previously LORIS would crash and show a blank page on 500 errors OR mistakenly show a 404 page.
This was because
the try-catch in Module only had a catch case forofNotFound
exceptions. Thus all exceptions were treated as 404 as a result even though it was wrongreasons
.On top of this, the actual exception message would be swallowed and would not appear in the error logs, making things very difficult to debug.
This PR fixes this issues and serves well-decorated 500 pages containing a message to the user. A special message is returned for ConfigurationExceptions as they reflect errors on the user's part rather than on LORIS's part. The exception information is also logged to assist with debugging.
This resolves issue...
Should address numerous issues that have arisen in PRs #3921 #3881 #4162, maybe more.
To test this change...