summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2020-09-30 15:49:25 -0400
committerNick Vatamaniuc <nickva@users.noreply.github.com>2020-09-30 16:55:20 -0400
commiteaf13d35338fa4eecf660879c0b469c1db850a5b (patch)
tree0560619491d5f947c71ed924536adbfa3fbfedc5
parenta07413385b741e044ce9d7aa588c2918faacbebf (diff)
downloadcouchdb-eaf13d35338fa4eecf660879c0b469c1db850a5b.tar.gz
Fix error reporting when fetching replication filters
Don't unnecessarily unwrap the fetch error since `error_info/1` can already handle the current shape. Also, make sure to translate the reason to binary for consistency with the other filter fetching errors in the `couch_replicator_filters` module. Add a test to ensure we return the `filter_fetch_error` term as that is explicitly turned into a 404 error in chttpd, so we try to maintain compatibility with CouchDB <= 3.x code.
-rw-r--r--src/couch_replicator/src/couch_replicator_filters.erl2
-rw-r--r--src/couch_replicator/src/couch_replicator_job.erl5
-rw-r--r--src/couch_replicator/test/eunit/couch_replicator_transient_jobs_tests.erl17
3 files changed, 18 insertions, 6 deletions
diff --git a/src/couch_replicator/src/couch_replicator_filters.erl b/src/couch_replicator/src/couch_replicator_filters.erl
index 50c37335d..1cadce1dd 100644
--- a/src/couch_replicator/src/couch_replicator_filters.erl
+++ b/src/couch_replicator/src/couch_replicator_filters.erl
@@ -150,7 +150,7 @@ fetch_internal(DDocName, FilterName, Source) ->
couch_replicator_api_wrap:db_uri(Source),
couch_util:to_binary(CodeError)]
),
- throw({fetch_error, CodeErrorMsg})
+ throw({fetch_error, iolist_to_binary(CodeErrorMsg)})
end
after
couch_replicator_api_wrap:db_close(Db)
diff --git a/src/couch_replicator/src/couch_replicator_job.erl b/src/couch_replicator/src/couch_replicator_job.erl
index ed3d00d7b..eaa661e77 100644
--- a/src/couch_replicator/src/couch_replicator_job.erl
+++ b/src/couch_replicator/src/couch_replicator_job.erl
@@ -810,9 +810,8 @@ get_rep_id(JTx, Job, #{} = JobData) ->
try
couch_replicator_ids:replication_id(Rep)
catch
- throw:{filter_fetch_error, Error} ->
- Error1 = io_lib:format("Filter fetch error ~p", [Error]),
- reschedule_on_error(JTx, Job, JobData, Error1),
+ throw:{filter_fetch_error, _} = Error ->
+ reschedule_on_error(JTx, Job, JobData, {error, Error}),
exit({shutdown, finished})
end.
diff --git a/src/couch_replicator/test/eunit/couch_replicator_transient_jobs_tests.erl b/src/couch_replicator/test/eunit/couch_replicator_transient_jobs_tests.erl
index 25fc6a3ff..222d13809 100644
--- a/src/couch_replicator/test/eunit/couch_replicator_transient_jobs_tests.erl
+++ b/src/couch_replicator/test/eunit/couch_replicator_transient_jobs_tests.erl
@@ -31,7 +31,8 @@ transient_jobs_test_() ->
fun teardown/1,
[
?TDEF_FE(transient_job_is_removed, 10),
- ?TDEF_FE(posting_same_job_is_a_noop, 10)
+ ?TDEF_FE(posting_same_job_is_a_noop, 10),
+ ?TDEF_FE(transient_job_with_a_bad_filter, 10)
]
}
}
@@ -79,7 +80,19 @@ posting_same_job_is_a_noop({Source, Target}) ->
?assertEqual(Pid1, Pid2),
couch_replicator_test_helper:cancel(RepId1).
-
+
+transient_job_with_a_bad_filter({Source, Target}) ->
+ DDoc = #{<<"_id">> => <<"_design/myddoc">>},
+ couch_replicator_test_helper:create_docs(Source, [DDoc]),
+ Result = couch_replicator:replicate(#{
+ <<"source">> => couch_replicator_test_helper:db_url(Source),
+ <<"target">> => couch_replicator_test_helper:db_url(Target),
+ <<"continuous">> => true,
+ <<"filter">> => <<"myddoc/myfilter">>
+ }, ?ADMIN_USER),
+ ?assertMatch({error, #{<<"error">> := <<"filter_fetch_error">>}}, Result).
+
+
get_rep_id(Source, Target) ->
{ok, Id, _} = couch_replicator_parse:parse_transient_rep(#{
<<"source">> => couch_replicator_test_helper:db_url(Source),