[Why] Traceback (most recent call last): 4: from /c/compass-ci/sbin/compare:70:in `<main>' 3: from /c/compass-ci/lib/compare.rb:97:in `compare_by_template' 2: from /c/compass-ci/lib/compare.rb:128:in `create_groups_matrices' 1: from /c/compass-ci/lib/es_query.rb:21:in `multi_field_query' /c/compass-ci/lib/es_query.rb:54:in `build_mutli_field_subquery_body': undefined method `each' for nil:NilClass (NoMethodError) "compare_temlpate.yaml" may pass empty filter as input parameter
[How] exit when the filter is empty
Signed-off-by: Lu Weitao luweitaobe@163.com --- lib/es_query.rb | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/lib/es_query.rb b/lib/es_query.rb index 037213d..c027aa9 100644 --- a/lib/es_query.rb +++ b/lib/es_query.rb @@ -18,6 +18,10 @@ class ESQuery # Example @items: { key1 => value1, key2 => [value2, value3, ..], ...} # means to query: key1 == value1 && (key2 in [value2, value3, ..]) def multi_field_query(items, size: 10_000) + unless items + warn 'empty filter!' + exit + end query_fields = build_mutli_field_subquery_body items query = { query: {
On Thu, Nov 19, 2020 at 09:02:58AM +0800, Lu Weitao wrote:
[Why] Traceback (most recent call last): 4: from /c/compass-ci/sbin/compare:70:in `<main>' 3: from /c/compass-ci/lib/compare.rb:97:in `compare_by_template' 2: from /c/compass-ci/lib/compare.rb:128:in `create_groups_matrices' 1: from /c/compass-ci/lib/es_query.rb:21:in `multi_field_query' /c/compass-ci/lib/es_query.rb:54:in `build_mutli_field_subquery_body': undefined method `each' for nil:NilClass (NoMethodError) "compare_temlpate.yaml" may pass empty filter as input parameter
[How] exit when the filter is empty
Signed-off-by: Lu Weitao luweitaobe@163.com
lib/es_query.rb | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/lib/es_query.rb b/lib/es_query.rb index 037213d..c027aa9 100644 --- a/lib/es_query.rb +++ b/lib/es_query.rb @@ -18,6 +18,10 @@ class ESQuery # Example @items: { key1 => value1, key2 => [value2, value3, ..], ...} # means to query: key1 == value1 && (key2 in [value2, value3, ..]) def multi_field_query(items, size: 10_000)
- unless items
warn 'empty filter!'
exit
You can use 'return' instead.
'return' is end of a method, 'exit' is end of a process.
Don't use 'exit', unless you are sure you want to 'exit'.
Thanks, Yuanchao
On Thu, Nov 19, 2020 at 04:19:19PM +0800, Li Yuanchao wrote:
On Thu, Nov 19, 2020 at 09:02:58AM +0800, Lu Weitao wrote:
[Why] Traceback (most recent call last): 4: from /c/compass-ci/sbin/compare:70:in `<main>' 3: from /c/compass-ci/lib/compare.rb:97:in `compare_by_template' 2: from /c/compass-ci/lib/compare.rb:128:in `create_groups_matrices' 1: from /c/compass-ci/lib/es_query.rb:21:in `multi_field_query' /c/compass-ci/lib/es_query.rb:54:in `build_mutli_field_subquery_body': undefined method `each' for nil:NilClass (NoMethodError) "compare_temlpate.yaml" may pass empty filter as input parameter
[How] exit when the filter is empty
Signed-off-by: Lu Weitao luweitaobe@163.com
lib/es_query.rb | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/lib/es_query.rb b/lib/es_query.rb index 037213d..c027aa9 100644 --- a/lib/es_query.rb +++ b/lib/es_query.rb @@ -18,6 +18,10 @@ class ESQuery # Example @items: { key1 => value1, key2 => [value2, value3, ..], ...} # means to query: key1 == value1 && (key2 in [value2, value3, ..]) def multi_field_query(items, size: 10_000)
- unless items
warn 'empty filter!'
exit
You can use 'return' instead.
'return' is end of a method, 'exit' is end of a process.
yes
Don't use 'exit', unless you are sure you want to 'exit'.
lib/es_query.rb called by es-find and compare tools, seems need exit. and show warning message.
we also can return nil in this place, and exit in caller.
Thanks, weitao
Thanks, Yuanchao