[Groonga-commit] droonga/fluent-plugin-droonga at 88af0a6 [master] Report MissingSourceParameter error for queries without source

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Dec 26 18:34:20 JST 2013


YUKI Hiroshi	2013-12-26 18:34:20 +0900 (Thu, 26 Dec 2013)

  New Revision: 88af0a6a6fe77d82ad9e8f289aa4a8f519f2eb29
  https://github.com/droonga/fluent-plugin-droonga/commit/88af0a6a6fe77d82ad9e8f289aa4a8f519f2eb29

  Message:
    Report MissingSourceParameter error for queries without source

  Modified files:
    lib/droonga/searcher.rb
    test/unit/plugin/handler/test_search.rb

  Modified: lib/droonga/searcher.rb (+11 -1)
===================================================================
--- lib/droonga/searcher.rb    2013-12-26 18:30:06 +0900 (6d7bc80)
+++ lib/droonga/searcher.rb    2013-12-26 18:34:20 +0900 (8619cf2)
@@ -21,6 +21,14 @@ require "groonga"
 
 module Droonga
   class Searcher
+    class MissingSourceParameter < BadRequest
+      def initialize(query, queries)
+        super("The query #{query.inspect} has no source. " +
+                "Query must have a valid source.",
+              queries)
+      end
+    end
+
     class UnknownSource < NotFound
       def initialize(source, queries)
         super("The source #{source.inspect} does not exist. " +
@@ -53,7 +61,9 @@ module Droonga
       $log.trace("#{log_tag}: process_queries: sort: start")
       query_sorter = QuerySorter.new
       queries.each do |name, query|
-        query_sorter.add(name, [query["source"]])
+        source = query["source"]
+        raise MissingSourceParameter.new(name, queries) unless source
+        query_sorter.add(name, [source])
       end
       sorted_queries = query_sorter.tsort
       $log.trace("#{log_tag}: process_queries: sort: done")

  Modified: test/unit/plugin/handler/test_search.rb (+11 -0)
===================================================================
--- test/unit/plugin/handler/test_search.rb    2013-12-26 18:30:06 +0900 (24810f0)
+++ test/unit/plugin/handler/test_search.rb    2013-12-26 18:34:20 +0900 (6a123ab)
@@ -166,6 +166,17 @@ class SearchHandlerTest < Test::Unit::TestCase
                         },
                       })
       end
+
+      def test_no_source
+        assert_raise(Droonga::Searcher::MissingSourceParameter) do
+          search({
+                   "queries" => {
+                     "no-source-result" => {
+                     },
+                   },
+                 })
+        end
+      end
     end
 
     class OutputTest < self
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index