-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Using wrong flag to write to error log in ErrorHandler #3317
Comments
In this case, the test against The idea here is that we we add a tip to the log to remind the developer that if they want to see the error in their browser, they need to set There's an argument that we could add a new |
Please don't just close the issue. it is not resolved nor completed. I get the idea here. but I'm not sure you are correct. for example, there is no need for Let me elaborate.
Also, regarding the details, We may want to either:
So, what if I don't want to display the details of a log but I want to write details of the same log to send it to a backend? We need to understand the purpose of the flags: The The Back to my first post. the condition I mentioned IS NOT meant for display and the developer must have used Pay attention, the function name is Practical Example: I can send a pull request about this. |
Please reopen @akrabat |
As per your original report, the code is not using the wrong flag as the That is, the suggestion to change line 262 to |
Having said that, you have now provided additional information about an actual problem you have that you did not provide in the original report which shows that there is an issue to be addressed. It would have been helpful if you have provided the information about the production of invalid JSON at the start as we can now determine the correct resolution to your actual problem. |
I'm still uncertain about your understanding regarding the intention of the code. You can check where the function is called. On line 135 you can see that a response is returned and Am I wrong? please guide me so that I can help to fix it. |
As I now understand it, the actual problem is that we are adding a plain text string to the output provided by an error renderer, where that renderer's output may be a formatted output that is not plain text. My immediate ideas for resolution to this are that we could do one of:
|
You are correct that The intention of the |
Look at line 261. The second param is Now look at line 300. The second param is
In If you guys are certain about keeping the tip. It can happen on line 303. we can simply append the tip to the body. I'll open a PR tomorrow. |
This is how I'd change protected function writeToErrorLog(): void
{
$renderer = $this->callableResolver->resolve($this->logErrorRenderer);
$error = $renderer($this->exception, $this->logErrorDetails);
$this->logError($error);
} protected function respond(): ResponseInterface
{
$response = $this->responseFactory->createResponse($this->statusCode);
if ($this->contentType !== null && array_key_exists($this->contentType, $this->errorRenderers)) {
$response = $response->withHeader('Content-type', $this->contentType);
} else {
$response = $response->withHeader('Content-type', $this->defaultErrorRendererContentType);
}
if ($this->exception instanceof HttpMethodNotAllowedException) {
$allowedMethods = implode(', ', $this->exception->getAllowedMethods());
$response = $response->withHeader('Allow', $allowedMethods);
}
$renderer = $this->determineRenderer();
$body = call_user_func($renderer, $this->exception, $this->displayErrorDetails);
if ($body !== false) {
if (!$this->displayErrorDetails) {
$body .= "\nTips: To display error details in HTTP response ";
$body .= 'set "displayErrorDetails" to true in the ErrorHandler constructor.';
}
/** @var string $body */
$response->getBody()->write($body);
}
return $response;
} |
The important thing is that
is output to the log, not the the response. |
If the logErrorRenderer is not the plain text renderer then we must not render the tips message as this will break the structured format of the message that's been rendered. Closes slimphp#3317
In
ErrorHandler
at line 262, the condition is checked against the wrong flag.the condition must check against
$this->logErrorDetails
rather than$this->displayErrorDetails
. so the line would be:if (!$this->logErrorDetails) {
If the bug is valid, I can create a pull request to fix it.
More details: It seems
writeToErrorLog()
is used to save the logs properly somewhere and$this->displayErrorDetails
is used by the renderer to show the error details in realtime on the clientThe text was updated successfully, but these errors were encountered: