#1 2012-01-09 20:22:17
- debugger
- Member
- Registered: 2007-03-17
- Posts: 44
[Patch] Show errors in plugins.
Problem:
If you have a stupid mistake in your plugin, the error message gives no clue what the problem is. For example, following mistake in plugin source:
Code:
pa ckage GCPlugins::GCfilms::GCPluginKinopoisk_VdB;
gives error:
Fatal error with plugin GCKinopoisk_VdB
: Can't locate object method "new" via package "GCPlugins::GCfilms::GCPluginKinopoisk_VdB" (perhaps you forgot to load "GCPlugins::GCfilms::GCPluginKinopoisk_VdB"?) at (eval 1096) line 1.
The problem is in the code (GCPlugins.pm file):
Code:
foreach (glob "$dir/*.pm") { my $plugin = basename($_, '.pm')."\n"; next if $plugin =~ /Common/; eval "use GCPlugins::".$model."::$plugin"; (my $class = $plugin) =~ s/^GC/GCPlugin/; my $obj; eval "\$obj = new GCPlugins::".$model."::$class"; die "Fatal error with plugin $plugin : $@" if $@; $pluginsMap{$model}->{$obj->getName} = $obj; }
If the first eval finishes with error, it is completely ignored. But this error message is very important in case of troubles. Minor code reorganization:
Code:
foreach (glob "$dir/*.pm") { my $plugin = basename($_, '.pm')."\n"; next if $plugin =~ /Common/; (my $class = $plugin) =~ s/^GC/GCPlugin/; my $obj; eval "use GCPlugins::".$model."::$plugin; \$obj = new GCPlugins::".$model."::$class;"; die "Fatal error with plugin $plugin : $@" if $@; $pluginsMap{$model}->{$obj->getName} = $obj; }
makes the error message visible:
Fatal error with plugin GCKinopoisk_VdB
: Bareword "GCPlugins::GCfilms::GCPluginKinopoisk_VdB" not allowed while "strict subs" in use at .../lib/gcstar/GCPlugins/GCfilms/GCKinopoisk_VdB.pm line 11.
Compilation failed in require at (eval 1064) line 2.
BEGIN failed--compilation aborted at (eval 1064) line 2.
Note, that error message includes file name and line number, which greatly simplifies error fixing.
Last edited by debugger (2012-01-09 20:24:39)
Offline
#2 2012-01-12 10:15:39
Re: [Patch] Show errors in plugins.
Bonjour,
Merci, c'est effectivement très utile. Et ça m'a d'ailleurs permis de voir qu'il y avait des soucis dans quelques plugins existants (ils ne retournaient pas 1 à la fin)
Je viens de mettre ça dans SVN.
Offline
Should you have a problem using GCstar, you can open a bug report or request some support on GCstar forums.