diff --git a/lib/hexdocs/search/typesense.ex b/lib/hexdocs/search/typesense.ex index 16f4a53..d2d0e9f 100644 --- a/lib/hexdocs/search/typesense.ex +++ b/lib/hexdocs/search/typesense.ex @@ -34,7 +34,7 @@ defmodule Hexdocs.Search.Typesense do %{"success" => false, "error" => error, "document" => document} -> Logger.error( - "Failed to index search item for #{package} #{version}: #{inspect(document)}: #{inspect(error)}" + "Failed to index search item for #{package} #{version} for document #{inspect(document)}: #{inspect(error)}" ) end end) diff --git a/test/hexdocs/search_test.exs b/test/hexdocs/search_test.exs index a5841cc..271a370 100644 --- a/test/hexdocs/search_test.exs +++ b/test/hexdocs/search_test.exs @@ -124,6 +124,7 @@ defmodule Hexdocs.SearchTest do end) assert log =~ "[info] Failed to find search data for #{package} 1.0.0" + assert typesense_search(%{"q" => package, "query_by" => "package"}) == [] end test "logs an error message if search_data.js file has unexpected format", %{package: package} do @@ -134,6 +135,7 @@ defmodule Hexdocs.SearchTest do log = capture_log(fn -> run_upload(package, "1.0.0", files) end) assert log =~ "[error] Unexpected search_data format for #{package} 1.0.0" + assert typesense_search(%{"q" => package, "query_by" => "package"}) == [] end test "logs an error message if search_data.json cannot be decoded", %{package: package} do @@ -146,6 +148,8 @@ defmodule Hexdocs.SearchTest do assert log =~ "[error] Failed to decode search data json for #{package} 1.0.0: unexpected end of input at position 10" + + assert typesense_search(%{"q" => package, "query_by" => "package"}) == [] end test "logs an error message if search_data has empty items", %{package: package} do @@ -158,6 +162,8 @@ defmodule Hexdocs.SearchTest do assert log =~ "[error] Failed to extract search items and proglang from search data for #{package} 1.0.0" + + assert typesense_search(%{"q" => package, "query_by" => "package"}) == [] end test "logs an error message if search_data has no items", %{package: package} do @@ -170,6 +176,36 @@ defmodule Hexdocs.SearchTest do assert log =~ "[error] Failed to extract search items and proglang from search data for #{package} 1.0.0" + + assert typesense_search(%{"q" => package, "query_by" => "package"}) == [] + end + + test "logs errors when indexing incomplete search items", %{package: package} do + files = [ + {"index.html", "contents"}, + {"dist/search_data-0F918FFD.js", + """ + searchData={"items":[\ + {"type":"whatever"},\ + {"type":"function","title":"Example.test/4","doc":"does example things","ref":"Example.html#test/4"},\ + {"type":"module","title":"Example","doc":"example text","ref":"Example.html"}\ + ],"content_type":"text/markdown","producer":{"name":"ex_doc","version":[48,46,51,52,46,50]},\ + "proglang":"elixir"}\ + """} + ] + + log = capture_log(fn -> run_upload(package, "1.0.0", files) end) + + assert log =~ "[error] Failed to index search item for #{package} 1.0.0 for document " + assert log =~ "Field `doc` has been declared in the schema, but is not found in the document." + + # the valid documents should still be indexed + assert [_, _] = + typesense_search(%{ + "q" => "example", + "query_by" => "title", + "filter" => "proglang:elixir" + }) end defp queue_put_message(key) do