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/08/23 05:51:28 UTC
(couchdb) branch main updated: Account for another expected error in quickjs scanner
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/main by this push:
new 63c0bd5a8 Account for another expected error in quickjs scanner
63c0bd5a8 is described below
commit 63c0bd5a8ab9971005256c2bd48198138aa52c5a
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Fri Aug 23 00:04:46 2024 -0400
Account for another expected error in quickjs scanner
This is generated by our own dispatch loop [1] as a catch-all. It emits a
traceback so will always look different across engine. We handle it as an
expected error so it doesn't pollute the logs with false positives.
[1]
https://github.com/apache/couchdb/blob/d38f14f7d777b7cda79b9862ee304150ad3418ea/share/server/loop.js#L159
---
.../src/couch_quickjs_scanner_plugin.erl | 2 ++
.../test/couch_quickjs_scanner_plugin_tests.erl | 29 ++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl b/src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl
index ee8a76bcc..005488430 100644
--- a/src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl
+++ b/src/couch_quickjs/src/couch_quickjs_scanner_plugin.erl
@@ -520,6 +520,8 @@ expected_error({error, {_, <<"TypeError">>, _}}, {error, {_, <<"TypeError">>, _}
true;
expected_error({error, {_, {<<"TypeError">>, _}}}, {error, {_, {<<"TypeError">>, _}}}) ->
true;
+expected_error({error, {_, {<<"unnamed_error">>, _}}}, {error, {_, {<<"unnamed_error">>, _}}}) ->
+ 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 e91081f96..231b9b76c 100644
--- a/src/couch_quickjs/test/couch_quickjs_scanner_plugin_tests.erl
+++ b/src/couch_quickjs/test/couch_quickjs_scanner_plugin_tests.erl
@@ -26,6 +26,7 @@ couch_quickjs_scanner_plugin_test_() ->
?TDEF_FE(t_map_only, 10),
?TDEF_FE(t_vdu_only, 10),
?TDEF_FE(t_filter_only, 10),
+ ?TDEF_FE(t_filter_with_expected_error, 10),
?TDEF_FE(t_empty_ddoc, 10)
]
}.
@@ -231,6 +232,27 @@ t_filter_only({_, DbName}) ->
ok
end.
+t_filter_with_expected_error({_, DbName}) ->
+ ok = add_doc(DbName, ?DDOC1, ddoc_filter_error(#{})),
+ meck:reset(couch_scanner_server),
+ meck:reset(?PLUGIN),
+ config:set("couch_scanner_plugins", atom_to_list(?PLUGIN), "true", false),
+ wait_exit(10000),
+ ?assertEqual(1, num_calls(start, 2)),
+ case couch_server:with_spidermonkey() of
+ true ->
+ ?assertEqual(1, num_calls(complete, 1)),
+ ?assertEqual(1, num_calls(db, ['_', DbName])),
+ ?assertEqual(1, 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(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));
+ false ->
+ ok
+ end.
+
t_empty_ddoc({_, DbName}) ->
ok = add_doc(DbName, ?DDOC1, #{}),
meck:reset(couch_scanner_server),
@@ -333,6 +355,13 @@ ddoc_filter(Doc) ->
}
}.
+ddoc_filter_error(Doc) ->
+ Doc#{
+ filters => #{
+ f => <<"function(doc, req) {throw(\"foo\");}">>
+ }
+ }.
+
ddoc_view(Doc) ->
Doc#{
views => #{