[Rt-commit] rtir branch, 5.0/trap-whois-errors, created. 4.0.1rc1-231-gfafa059e

Jim Brandt jbrandt at bestpractical.com
Mon Jun 15 17:53:26 EDT 2020


The branch, 5.0/trap-whois-errors has been created
        at  fafa059e30ad2f4d7fafcd02d2478ab1c460a507 (commit)

- Log -----------------------------------------------------------------
commit fafa059e30ad2f4d7fafcd02d2478ab1c460a507
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Jun 15 17:34:53 2020 -0400

    Catch parse failures from Net::Whois::Object
    
    Following the update of Net::Whois::RIPE in 1ffa0fb951,
    creating a new object can error. The module dies, so
    as a first step in handling these errors, add an eval
    to catch the failure and provide a message to the user.

diff --git a/html/RTIR/Tools/Elements/GetEmailFromIP b/html/RTIR/Tools/Elements/GetEmailFromIP
index 0d768be7..f6d4f81f 100644
--- a/html/RTIR/Tools/Elements/GetEmailFromIP
+++ b/html/RTIR/Tools/Elements/GetEmailFromIP
@@ -62,16 +62,28 @@ unless ( $iterator ) {
 
 $field ||= 'notify';
 
-my @objects = Net::Whois::Object->new($iterator);
+# Trap possible failures when parsing results
+# Net::Whois currently dies in some cases, so we need to eval
+eval {
+    my @objects = Net::Whois::Object->new($iterator);
+};
+
 my @res;
-foreach my $obj (@objects) {
-    foreach my $attr ( grep lc $_ eq lc $field, $obj->attributes ) {
-        push @res, $obj->$attr();
-    }
+if ( $@ ) {
+    RT->Logger->warn('Unable to parse WHOIS results for query ' . $args{'Query'});
+    RT->Logger->debug($@);
+    $$error = loc('Unable to parse results from WHOIS lookup');
 }
-unless ( @res ) {
-    $$error = loc("Whois server response did not include field '[_1]'", $field);
-    return;
+else {
+    foreach my $obj (@objects) {
+        foreach my $attr ( grep lc $_ eq lc $field, $obj->attributes ) {
+            push @res, $obj->$attr();
+        }
+    }
+    unless ( @res ) {
+        $$error = loc("Whois server response did not include field '[_1]'", $field);
+        return;
+    }
 }
 
 ($$address) = grep defined && length, @res;

-----------------------------------------------------------------------


More information about the rt-commit mailing list