maxmind / GeoIP2-perl

Perl API for MaxMind's GeoIP2 web services and databases
https://metacpan.org/release/GeoIP2/
Other
18 stars 11 forks source link

Giving a bad/missing file to GeoIP2::Database::Reader does not throw an exception from the constructor #43

Closed autarch closed 5 years ago

autarch commented 7 years ago
use strict;
use warnings;

use Try::Tiny;
use GeoIP2::Database::Reader;

my $countryReader;
try {
    print "opening Country\n";
    $countryReader = GeoIP2::Database::Reader->new(
        file    => '/usr/share/GeoIP/GeoIP2-INVALID.mmdb',
        locales => ['en']
    );
}
catch {
    print "Error:" . $_ . "\n";
};

The problem is that the actual error is thrown by the MaxMind::DB::Reader object, which we build lazily. I think we can probably make that attribute non-lazy. Then the file will be checked immediately.

oschwald commented 5 years ago

Closing as we are no longer making enhancements to this module.