elixir-inspector / ua_inspector

User agent parser library
Apache License 2.0
127 stars 23 forks source link

error with bots #7

Closed maxguzenski closed 7 years ago

maxguzenski commented 7 years ago

I'm receiving a lot of this on production:

exit: ** (exit) :function_clause
  File "lib/regex.ex", line 159, in Regex.match?(~r/(?:^|[^A-Z0-9-_]|[^A-Z0-9-]_|sprd-)(?:360Spider(-Image|-Video)?)/, nil)
  File "lib/ua_inspector/parser/bot.ex", line 31, in UAInspector.Parser.Bot.parse/2
  File "lib/ua_inspector/parser.ex", line 52, in UAInspector.Parser.parse/1
  File "lib/ua_inspector/server.ex", line 23, in UAInspector.Server.handle_call/3
  File "gen_server.erl", line 615, in :gen_server.try_handle_call/4
  File "gen_server.erl", line 647, in :gen_server.handle_msg/5
  File "proc_lib.erl", line 247, in :proc_lib.init_p_do_apply/3
  Module "Elixir.UAInspector.Server", in UAInspector.Server.init(:Argument__1)
mneudert commented 7 years ago

It looks like you are not passing any user agent in to be parsed. An example for that might be calling Plug.Conn.get_req_header/2 when no header exists.

By arbitrary (and perhaps sort of bad) decision the interface currently actually requires a string so you should be fine by modifying your lookup a bit:

UAInspector.parse(user_agent || "")

That way your errors should go away until I have whipped together a new release so these failures are prevented in the first place...

mneudert commented 7 years ago

I have just released a new version with the appropriate fix in place. If your problem still persists please re-open this issue or open a new one.