News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Stack Trace

Started by Arantor, October 10, 2014, 06:47:04 PM

Previous topic - Next topic

Arantor

Link to Mod

When errors are tracked when this mod is installed, a stack trace will be captured with them to be able to identify the code path involved.

If you do not understand what this means, this mod is likely not appropriate for you.

Licence: CC0 licence

live627


ryan_dwight

how to remove this

Notice: Undefined index: file in /home/ptcb/public_html/Sources/Errors.php on line 152

Notice: Undefined index: file in /home/ptcb/public_html/Sources/Errors.php on line 154

Notice: Undefined index: file in /home/ptcb/public_html/Sources/Errors.php on line 159

Notice: Undefined index: line in /home/ptcb/public_html/Sources/Errors.php on line 159

on top of my site on the admin page only

Arantor

That means you have *other* errors, since this one only appears under very specific circumstances - and only after other errors are in the log.

You should figure out what the other error is...

vbgamer45

Nice mod should be an option part of SMF.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Diego Andrés


SMF Tricks - Free & Premium Responsive Themes for SMF.

Shambles

What annoys me about this mod, is that I didn't think of it first  :o

Incredibly useful, I have to say  :laugh:



Quote from: ryan_dwight
how to remove this

Notice: Undefined index: file in /home/ptcb/public_html/Sources/Errors.php on line 152

Notice: Undefined index: file in /home/ptcb/public_html/Sources/Errors.php on line 154

Notice: Undefined index: file in /home/ptcb/public_html/Sources/Errors.php on line 159

Notice: Undefined index: line in /home/ptcb/public_html/Sources/Errors.php on line 159

I too am seeing those in my error log.




Sources/Errors.php

	
	
	
foreach (
debug_backtrace() as $this_error)
	
	
	
{
	
	
	
	
// We don't need to log the error handler itself.
	
	
	
	
if (
substr($this_error['file'], -10) == 'Errors.php' && $this_error['function'] == 'log_error')
	
	
	
	
	
continue;
	
	
	
	
if (
substr($this_error['file'], -8) == 'Subs.php' && $this_error['function'] == 'error_handler')
	
	
	
	
	
continue;

	
	
	
	
// Certain anonymous calls do not end up in this fashion.
	
	
	
	
$frame = array(
====>
	
	
	
	
	
'line' => $smcFunc['htmlspecialchars'](strtr($this_error['file'], $repl) . ':' $this_error['line']),
	
	
	
	
	
'function' => $smcFunc['htmlspecialchars']((!empty($this_error['class']) ? $this_error['class'] . '->' '') . $this_error['function']),
	
	
	
	
);
	
	
	
	
if (
$frame['line'] != ':')
	
	
	
	
	
$stack[] = $frame;
	
	
	
}



No real biggie as the evaluation has already been output. Could the debug_backtrace() function be going out of bounds?

Arantor

Oh, that's interesting.

Backtraces that don't have line or file numbers... odd, because that's not supposed to be possible :P

Will investigate why PHP's backtrace function seems like it is broken...

dougiefresh

My suggestion on this would be to change this:
foreach (debug_backtrace() as $this_error)
{
// We don't need to log the error handler itself.
if (substr($this_error['file'], -10) == 'Errors.php' && $this_error['function'] == 'log_error')
continue;
if (substr($this_error['file'], -8) == 'Subs.php' && $this_error['function'] == 'error_handler')
continue;

// Certain anonymous calls do not end up in this fashion.
$frame = array(
'line' => $smcFunc['htmlspecialchars'](strtr($this_error['file'], $repl) . ':' . $this_error['line']),
'function' => $smcFunc['htmlspecialchars']((!empty($this_error['class']) ? $this_error['class'] . '->' : '') . $this_error['function']),
);
if ($frame['line'] != ':')
$stack[] = $frame;
}

to this:
foreach (debug_backtrace() as $this_error)
{
if (isset($this_error['file']))
{
// We don't need to log the error handler itself.
if (substr($this_error['file'], -10) == 'Errors.php' && $this_error['function'] == 'log_error')
continue;
if (substr($this_error['file'], -8) == 'Subs.php' && $this_error['function'] == 'error_handler')
continue;

// Certain anonymous calls do not end up in this fashion.
$frame = array(
'line' => $smcFunc['htmlspecialchars'](strtr($this_error['file'], $repl) . ':' . $this_error['line']),
'function' => $smcFunc['htmlspecialchars']((!empty($this_error['class']) ? $this_error['class'] . '->' : '') . $this_error['function']),
);
if ($frame['line'] != ':')
$stack[] = $frame;
}
}
if (!empty($stack))
$stack_trace = serialize(array_reverse($stack));
}

Arantor

That would cause certain things to be skipped. Better solution required. :-/

This is not helped by the fact I am not on my dev box until it gets repaired...

dougiefresh

Personally, I think it would be nice if the stack trace was initially hidden and clicking on a link would display it.  That's just my personal opinion...

Arantor

I wrote this mod for my own personal use and thought it was nice to share, another instance of something I have apparently not yet learned to stop doing. I deliberately did not do that because I was trying to keep the edits to a minimum. In any case if you have errors in the log, the entire point is that this helps you *stop having them*.

As in, what benefit is there to hiding the traces? If you don't want the trace for an error, get rid of the error.

dougiefresh

That's true.  It just was a suggestion.  Thank you for the mod!  It's very helpful....

Sabre™

Thank You Arantor.
I was searching for something similar which was around years ago, but couldn't find it, and found this.
This is a Very useful modification.
Cheers
Do NOT give admin and/or ftp details to just anybody, see if they are trust worthy first!!  Do your homework ;)


dougiefresh

Quote from: Arantor on November 06, 2014, 06:23:45 PM
Quote from: dougiefresh on November 06, 2014, 05:05:01 PM
My suggestion on this would be to change this:
foreach (debug_backtrace() as $this_error)
{
// We don't need to log the error handler itself.
if (substr($this_error['file'], -10) == 'Errors.php' && $this_error['function'] == 'log_error')
continue;
if (substr($this_error['file'], -8) == 'Subs.php' && $this_error['function'] == 'error_handler')
continue;

// Certain anonymous calls do not end up in this fashion.
$frame = array(
'line' => $smcFunc['htmlspecialchars'](strtr($this_error['file'], $repl) . ':' . $this_error['line']),
'function' => $smcFunc['htmlspecialchars']((!empty($this_error['class']) ? $this_error['class'] . '->' : '') . $this_error['function']),
);
if ($frame['line'] != ':')
$stack[] = $frame;
}

to this:
foreach (debug_backtrace() as $this_error)
{
if (isset($this_error['file']))
{
// We don't need to log the error handler itself.
if (substr($this_error['file'], -10) == 'Errors.php' && $this_error['function'] == 'log_error')
continue;
if (substr($this_error['file'], -8) == 'Subs.php' && $this_error['function'] == 'error_handler')
continue;

// Certain anonymous calls do not end up in this fashion.
$frame = array(
'line' => $smcFunc['htmlspecialchars'](strtr($this_error['file'], $repl) . ':' . $this_error['line']),
'function' => $smcFunc['htmlspecialchars']((!empty($this_error['class']) ? $this_error['class'] . '->' : '') . $this_error['function']),
);
if ($frame['line'] != ':')
$stack[] = $frame;
}
}
if (!empty($stack))
$stack_trace = serialize(array_reverse($stack));
}

That would cause certain things to be skipped. Better solution required. :-/

This is not helped by the fact I am not on my dev box until it gets repaired...
Sorry bout bumping this thread again, as well as rehashing this topic.  But I found something that works....

In Sources/Errors.php:
Code (Find) Select
foreach (debug_backtrace() as $this_error)
{
// We don't need to log the error handler itself.
if (substr($this_error['file'], -10) == 'Errors.php' && $this_error['function'] == 'log_error')
continue;
if (substr($this_error['file'], -8) == 'Subs.php' && $this_error['function'] == 'error_handler')
continue;

// Certain anonymous calls do not end up in this fashion.
$frame = array(
'line' => $smcFunc['htmlspecialchars'](strtr($this_error['file'], $repl) . ':' . $this_error['line']),
'function' => $smcFunc['htmlspecialchars']((!empty($this_error['class']) ? $this_error['class'] . '->' : '') . $this_error['function']),
);
if ($frame['line'] != ':')
$stack[] = $frame;
}

to this:
Code (Replace) Select

foreach (debug_backtrace() as $this_error)
{
// We don't need to log the error handler itself.
if (isset($this_error['file']) && substr($this_error['file'], -10) == 'Errors.php' && $this_error['function'] == 'log_error')
continue;
if (isset($this_error['file']) && substr($this_error['file'], -8) == 'Subs.php' && $this_error['function'] == 'error_handler')
continue;

// Certain anonymous calls do not end up in this fashion.
$frame = array(
'line' => isset($this_error['file']) ? $smcFunc['htmlspecialchars'](strtr($this_error['file'], $repl) . ':' . $this_error['line']) : '',
'function' => $smcFunc['htmlspecialchars']((!empty($this_error['class']) ? $this_error['class'] . '->' : '') . $this_error['function']),
);
if ($frame['line'] != ':')
$stack[] = $frame;
}

Hope this is useful to someone....

aegersz

#15
I like this one but the mod is not working on my 2.0.15 system.

no errors (from this mod or from PHP), no code path data displayed.

tested by triggering known errors - i wonder what could be wrong ?

EDIT/FIXED:

In Admin > Configuration > Server Settings > General  > Disable evaluation of templates must be on/selected

SMF 2.0.15 has it OFF by default

The configuration of my Linux VPS (SMF 2.0 with 160+ mods & some assorted manual tweaks) can be found here and notes on my mods can be found here (warning: those links will take you to a drug related forum). My (House) music DJ dedication page is here

dougiefresh

@aegersz:  IMO, that report is definitely a bug that should be fixed as well....

aegersz

@dougiefresh

? i am not sure what you mean - i just had the setting wrong
The configuration of my Linux VPS (SMF 2.0 with 160+ mods & some assorted manual tweaks) can be found here and notes on my mods can be found here (warning: those links will take you to a drug related forum). My (House) music DJ dedication page is here

-Rock Lee-

It seems like a good thing, I'm going to prove it, it's going, thank you very much for sharing @Arantor


Regards!
¡Regresando como cual Fenix! ~ Bomber Code
Ayudas - Aportes - Tutoriales - Y mucho mas!!!

dougiefresh

Quote from: aegersz on February 11, 2018, 03:55:46 AM
@dougiefresh

? i am not sure what you mean - i just had the setting wrong
IMO, the stack trace should be visible regardless of whether that setting is ON or OFF.  That's my opinion, and that's why I'm calling it a bug to possibly be fixed....

Advertisement: