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

require PIWIK_PRINT_ERROR_BACKTRACE for exception backtraces in logs #16640

Merged
merged 11 commits into from Nov 4, 2020

Conversation

diosmosis
Copy link
Member

No description provided.

@diosmosis diosmosis added the Needs Review PRs that need a code review label Oct 31, 2020
@diosmosis diosmosis added this to the 4.0.0-RC milestone Oct 31, 2020
@@ -76,6 +76,10 @@ private function getMessage($exception)

private function getStackTrace($exception)
{
if (!\Piwik_ShouldPrintBackTraceWithMessage()) {
Copy link
Member

Choose a reason for hiding this comment

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

@diosmosis can we also check all other places where we use getTraceAsString()?

…ble which always checks if should print stacktrace
'message' => $e->getMessage(),
'backtrace' => $e->getTraceAsString(),
$logger->debug('Unable to unserialize a string: {exception} (string = {string})', [
'exception' => $e,
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't using the exception object here cause a cast to string when it's used in the message? And __toString will show the message and the (full) backtrace. Or does the Monologger do some magic here to use the ExceptionToTextProcessor?

Copy link
Member Author

Choose a reason for hiding this comment

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

to my understanding, ExceptionToTextProcessor should convert the 'exception' value to a string

if (!$shouldPrintBacktrace) {
return $exception->getMessage();
$message = $exception->getMessage() . "\n" . self::BACKTRACE_OMITTED_MESSAGE;
Copy link
Member

Choose a reason for hiding this comment

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

fyi the message again might not be needed? In my case it causes the exception message to be shown twice
image

At least it happened when I triggered an exception in Common::safe_unserialize() and thne it went into the ExceptionToTextProcessor::__invoke. I reckon the trace does not need to append the message again

Copy link
Member

Choose a reason for hiding this comment

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

I see it might be needed because of eg https://github.com/matomo-org/matomo/pull/16640/files#diff-7aeb867200acd3d0c23432f4b94edae59f9549e2b20160b83bd165830e5e2042L208

The method name might be bit misleading as it gets the message and the trace?

@diosmosis diosmosis merged commit 6b12f37 into 4.x-dev Nov 4, 2020
@diosmosis diosmosis deleted the exception-log-tweak branch November 4, 2020 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants