[gimp-perl] Improve exceptions keeping user-source location.



commit c8bddffa2bff9a4d6c7fe721855fbdc715d14c65
Author: Ed J <edj src gnome org>
Date:   Wed May 14 22:44:09 2014 +0100

    Improve exceptions keeping user-source location.

 Gimp.pm    |   15 ++++++++-------
 Net/Net.pm |    4 ++--
 TODO       |    2 +-
 3 files changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/Gimp.pm b/Gimp.pm
index fe5fc88..382799d 100644
--- a/Gimp.pm
+++ b/Gimp.pm
@@ -281,11 +281,12 @@ sub ignore_functions(@) {
    @ignore_function{ _}++;
 }
 
-sub recroak {
+sub recroak { $_[0] =~ /\n$/ ? die shift : croak shift; }
+sub exception_strip {
   my ($file, $e) = @_;
-  $file =~ s#\.[^\.]*$##; # cheat to allow Gimp[.pm] to match from Gimp/Net
-  die $e unless $e =~ s# at $file\S* line \d+\.\n\Z##;
-  croak $e;
+  $file =~ s#\..*##;
+  $e =~ s# at $file\S+ line \d+\.\n\Z##;
+  $e;
 }
 sub AUTOLOAD {
   my ($class,$name) = $AUTOLOAD =~ /^(.*)::(.*?)$/;
@@ -300,7 +301,7 @@ sub AUTOLOAD {
       *{$AUTOLOAD} = sub {
        shift unless ref $_[0];
        my @r = eval { &$ref };
-       recroak __FILE__, $@ if $@; wantarray ? @r : $r[0];
+       recroak exception_strip(__FILE__, $@) if $@; wantarray ? @r : $r[0];
       };
       goto &$AUTOLOAD;
     } elsif (UNIVERSAL::can($interface_pkg,$sub)) {
@@ -308,7 +309,7 @@ sub AUTOLOAD {
       *{$AUTOLOAD} = sub {
        shift unless ref $_[0];
        my @r = eval { &$ref };
-       recroak __FILE__, $@ if $@; wantarray ? @r : $r[0];
+       recroak exception_strip(__FILE__, $@) if $@; wantarray ? @r : $r[0];
       };
       goto &$AUTOLOAD;
     } elsif (gimp_procedural_db_proc_exists($sub)) {
@@ -318,7 +319,7 @@ sub AUTOLOAD {
        unshift @_, $sub;
        warn "$$-gimp_call_procedure{1}(@_)" if $Gimp::verbose;
        my @r = eval { gimp_call_procedure (@_) };
-       recroak __FILE__, $@ if $@; wantarray ? @r : $r[0];
+       recroak exception_strip(__FILE__, $@) if $@; wantarray ? @r : $r[0];
       };
       goto &$AUTOLOAD;
     }
diff --git a/Net/Net.pm b/Net/Net.pm
index 3ffd061..10e3c3b 100644
--- a/Net/Net.pm
+++ b/Net/Net.pm
@@ -102,7 +102,7 @@ sub gimp_call_procedure {
         print $trace_res $trace;
       }
    }
-   Gimp::recroak(__FILE__, $die_text) if $die_text;
+   Gimp::recroak(Gimp::exception_strip(__FILE__, $die_text)) if $die_text;
    wantarray ? @response : $response[0];
 }
 
@@ -321,7 +321,7 @@ sub handle_request($) {
            $trace_res = "";
         }
          @args = eval { Gimp->$function(@args) };
-        unshift @args, $@;
+        unshift @args, Gimp::exception_strip(__FILE__, $@);
         unshift @args, $trace_res if $req eq "TRCE";
         senddata $fh, args2net(1, @args);
          Gimp::set_trace(0) if $req eq "TRCE";
diff --git a/TODO b/TODO
index d36568f..21999e8 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,5 @@
 Items as of 2014-04-29 (by Ed J)
 * possible killer app: https://mail.gnome.org/archives/gimp-developer-list/2014-April/msg00017.html
-* jpegoptim and pngcrush save-handlers
 * gimp-plugins-refresh: load is
   app/plug-in/gimppluginmanager.c:gimp_plug_in_manager_query_new, closedown
   is ./app/plug-in/gimppluginmanager.c:gimp_plug_in_manager_exit
@@ -8,6 +7,7 @@ Items as of 2014-04-29 (by Ed J)
   PDB call added in tools/pdbgen/pdb/gimp.pdb
 * <Load> and <Save> need any registration as such done in Gimp::Fu - see pod and e/dataurl
 * Test Gimp::Fu menupath <Load>/<Save>/<Image>/<Toolbox>/<None>
+* jpegoptim and pngcrush save-handlers
 * e/fade-alpha should generate buttons, not hardcode
 * Gimp/Lib.xs is huge, and not very XS-y - lots of it is manually
   pushing GIMP data structures onto perl stack and vice versa. Figure


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]