You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2024/10/17 21:50:03 UTC

(couchdb) branch another-false-positive-for-qjs-scanner created (now 12b6117ca)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch another-false-positive-for-qjs-scanner
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at 12b6117ca Handle another expected error in the scanner

This branch includes the following new commits:

     new 12b6117ca Handle another expected error in the scanner

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(couchdb) 01/01: Handle another expected error in the scanner

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch another-false-positive-for-qjs-scanner
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 12b6117ca57691bc88d9a16c390e25077b468611
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Thu Oct 17 17:47:39 2024 -0400

    Handle another expected error in the scanner
    
    It's the same idea as `SyntaxError` and `TypeErorrs` above.
    
    While at it improve the filter test to use individual ddocs for each error.
    This way one error or crash won't influence the others.
---
 .../src/couch_quickjs_scanner_plugin.erl           |  2 ++
 .../test/couch_quickjs_scanner_plugin_tests.erl    | 28 +++++++++++++++-------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl b/src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl
index c9fe96a2b..2e889306b 100644
--- a/src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl
+++ b/src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl
@@ -544,6 +544,8 @@ expected_error({error, {_, {<<"unnamed_error">>, _}}}, {error, {_, {<<"unnamed_e
     true;
 expected_error({error, {_, {<<"SyntaxError">>, _}}}, {error, {_, {<<"SyntaxError">>, _}}}) ->
     true;
+expected_error({error, {_, {<<"ReferenceError">>, _}}}, {error, {_, {<<"ReferenceError">>, _}}}) ->
+    true;
 expected_error(_, _) ->
     false.
 
diff --git a/src/couch_quickjs/test/couch_quickjs_scanner_plugin_tests.erl b/src/couch_quickjs/test/couch_quickjs_scanner_plugin_tests.erl
index 566666177..5e7b25744 100644
--- a/src/couch_quickjs/test/couch_quickjs_scanner_plugin_tests.erl
+++ b/src/couch_quickjs/test/couch_quickjs_scanner_plugin_tests.erl
@@ -235,7 +235,11 @@ t_filter_only({_, DbName}) ->
     end.
 
 t_filter_with_expected_error({_, DbName}) ->
-    ok = add_doc(DbName, ?DDOC1, ddoc_filter_error(#{})),
+    % Put filters with errors in different ddocs so than each be tested in isolation
+    ok = add_doc(DbName, <<"_design/ddoc_custom_error">>, ddoc_filter_custom_error(#{})),
+    ok = add_doc(DbName, <<"_design/ddoc_type_error">>, ddoc_filter_type_error(#{})),
+    ok = add_doc(DbName, <<"_design/ddoc_syntax_error">>, ddoc_filter_syntax_error(#{})),
+    ok = add_doc(DbName, <<"_design/ddoc_reference_error">>, ddoc_filter_reference_error(#{})),
     meck:reset(couch_scanner_server),
     meck:reset(?PLUGIN),
     config:set("couch_scanner_plugins", atom_to_list(?PLUGIN), "true", false),
@@ -245,9 +249,9 @@ t_filter_with_expected_error({_, DbName}) ->
         true ->
             ?assertEqual(1, num_calls(complete, 1)),
             ?assertEqual(1, num_calls(db, ['_', DbName])),
-            ?assertEqual(1, num_calls(ddoc, ['_', DbName, '_'])),
+            ?assertEqual(4, num_calls(ddoc, ['_', DbName, '_'])),
             ?assertEqual(0, couch_stats:sample([couchdb, query_server, process_error_exits])),
-            ?assertEqual(10, couch_stats:sample([couchdb, query_server, process_errors])),
+            ?assertEqual(40, couch_stats:sample([couchdb, query_server, process_errors])),
             ?assertEqual(0, couch_stats:sample([couchdb, query_server, process_exits])),
             % start, complete and no warning as we expected the error, so 2 total only
             ?assertEqual(2, log_calls(warning));
@@ -397,12 +401,17 @@ ddoc_filter(Doc) ->
         }
     }.
 
-ddoc_filter_error(Doc) ->
-    Doc#{
-        filters => #{
-            f => <<"function(doc, req) {throw(\"foo\");}">>
-        }
-    }.
+ddoc_filter_custom_error(Doc) ->
+    Doc#{filters => #{f => <<"function(doc, req) {throw(\"foo\");}">>}}.
+
+ddoc_filter_type_error(Doc) ->
+    Doc#{filters => #{f => <<"function(doc, req){if(doc.missing.foo){return false;}}">>}}.
+
+ddoc_filter_syntax_error(Doc) ->
+    Doc#{filters => #{f => <<"function(doc, req){JSON.parse([]); return true;}">>}}.
+
+ddoc_filter_reference_error(Doc) ->
+    Doc#{filters => #{f => <<"function(doc, req){if(potato){return true;}}">>}}.
 
 ddoc_view(Doc) ->
     Doc#{
@@ -461,6 +470,7 @@ ddoc_view(Doc) ->
             },
             v_type_error => #{map => <<"function(doc){emit(doc.missing.foo,1);}">>},
             v_syntax_error => #{map => <<"function(doc){emit(JSON.parse([]),1);}">>},
+            v_reference_error => #{map => <<"function(doc){emit(potato,1);}">>},
             v_expr_fun1 => #{map => <<"(function(doc) {emit(1,2)})\n">>},
             v_expr_fun2 => #{map => <<"(function(doc) {emit(3,4)});">>},
             v_expr_fun3 => #{map => <<"y=9;\n(function(doc) {emit(5,y)})">>},