Help - Search - Members - Calendar
Full Version: Plugin Death Errors.
Movable Type Community Forum > Additional Resources > Plugin Development and Usage
druidic816
Is there a way to get more detailed error messages when a plugin dies? My website logs errors, but it doesn't log these plugin errors. All I see is stuff like this in the MT activity log:

2005.12.20 23:29:48 [IP Address] Junk Filter Moderate Via Delay died with:

Can I get anything more helpful?
sarah
This is probably something the plugin author would need to add to the plugin code. But I see on the ModerateViaDelay page that the plugin dies with TrackBacks. Is that what you're seeing?
druidic816
QUOTE (sarah @ Dec 21 2005, 04:47 AM)
This is probably something the plugin author would need to add to the plugin code. But I see on the ModerateViaDelay page that the plugin dies with TrackBacks. Is that what you're seeing?
*


I'm actually the plugin author. It mysteriously dies under other conditions, too. I can't even figure out which line of code I need to be looking at, or anything.
TweezerMan
Your plugin is not recording an error message in the MT Activity Log because of a bug in MT's code. This is from lib/MT/JunkFilter.pm, lines 52-58:
CODE
   # Run all the registered filters & average their results.
   foreach my $filter (@MT::JunkFilters) {
       my ($score, $log) = eval { $filter->{code}->($obj) };
       if ($@) {
           MT->instance->log(MT->translate("Junk Filter [_1] died with: [_2]", ($filter->{name} || (MT->translate("Unnamed Junk Filter"))), $@));
           next;
       }

Your plugin filter is run in the eval block at line 54, and if an error is returned from the eval, MT is supposed to log the error message in the Activity Log (line 56).

If an error message is returned from an eval block, the error message is stored in the perl variable $@. The problem with the above code is that, in the line that is actually logging the error (line 56), the function MT->translate("Unnamed Junk Filter") executes an eval block of its own and sets $@ before $@ can be read, wiping out your plugin's error message. Usually, the MT->translate function will execute without error, so $@ will be set to the empty string (""), and this is what MT ends up logging as your plugin's error message.

To correct this bug, the code should save the error message in a separate variable before attempting to translate and log the error message:
CODE
   # Run all the registered filters & average their results.
   foreach my $filter (@MT::JunkFilters) {
       my ($score, $log) = eval { $filter->{code}->($obj) };
       if ($@) {
           my $errmsg = $@;
           MT->instance->log(MT->translate("Junk Filter [_1] died with: [_2]", ($filter->{name} || (MT->translate("Unnamed Junk Filter"))), $errmsg));
           next;
       }

1) Line inserted at line 56, saving the error message in $@ in the variable $errmsg.
2) At line 57, replace $@ variable at the end of line with $errmsg.

With these changes made to the MT code, the following message is now recorded in the Activity Log when a trackback is received:
QUOTE
Junk Filter Moderate Via Delay died with: Can't call method "entry_id" without a package or object reference at C:\Apache2\www\mt3\plugins\ModerateViaDelay.pl line 172.

Line 172 of ModerateViaDelay.pl is the following code:
CODE
       $entry = MT::Entry->load(($obj->tb_id)->entry_id);

This code is trying to use a trackback ID number to load its corresponding entry, but is not doing it correctly.

$obj is a trackback ping (MT::TBPing object). $obj->tb_id only returns the corresponding MT::Trackback ID number (an integer), not any kind of object, so ($obj->tb_id)->entry_id is always going to result in an error.

To load an entry from a trackback ping ID, you'd need code something like the following, which uses the trackback ID to load the corresponding MT::Trackback object, gets the entry ID number, then loads that entry:
CODE
       $entry = MT::Entry->load(MT::Trackback->load($obj->tb_id)->entry_id);

Hope this helps...
sarah
A bug report does exist for this behaviour, so will be addressed in a future version.
druidic816
QUOTE (TweezerMan @ Dec 22 2005, 08:18 AM)
Your plugin is not recording an error message in the MT Activity Log because of a bug in MT's code.

(etc)

To load an entry from a trackback ping ID, you'd need code something like the following, which uses the trackback ID to load the corresponding MT::Trackback object, gets the entry ID number, then loads that entry:
CODE
       $entry = MT::Entry->load(MT::Trackback->load($obj->tb_id)->entry_id);

Hope this helps...
*



That helped tremendously. Everything seems to be working great now. Thanks!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.