Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

how to handle error? #4

Copy link
Copy link

Description

@Isma399
Issue body actions

Hello,
thanks for this lib.
We try to use it to localize mail sender, testing step was ok with some ips.
But passing it in prod breaks.
Is there a way to handle error when IP is in mmdb but not data :

# cat test.lua
local mm = require 'maxminddb'
local db = mm.open('/var/lib/libmaxminddb/GeoLite2-City.mmdb')

function geoip(ip)
    local res, status = db:lookup(ip)
    return res:get("country", "iso_code")
end

for k, ip in pairs({'8.8.8.8', '165.72.200.98'}) do
    print(ip, geoip(ip))
end

Script breaks on 165.72.200.98 :

# lua test.lua
8.8.8.8 US
lua: The lookup path does not match the data (key that doesn't exist, array index bigger than the array, expected array or map where none exists)
stack traceback:
        [C]: in function 'get'
        test.lua:6: in function 'geoip'
        test.lua:10: in main chunk
        [C]: ?
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.