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

vatamane pushed a commit to branch even-more-replicator-dialyzer-cleanup
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 9c7987c09dc1e14a8b0ae10f66038c3fc691f20a
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Thu Jul 14 11:23:16 2022 -0400

    Clean up unused code and invalid spec from replicator
    
    Invalid specs confused dialyzer.
    
    For bulk_docs response handling it detected another left-over clause
    from local endpoint support.
    
    It also found un-nessessarily broad case matches in
    couch_replicator_auth_session.
---
 .../src/couch_replicator_api_wrap.erl              | 39 +++-------------------
 .../src/couch_replicator_auth_session.erl          |  6 ++--
 .../src/couch_replicator_doc_processor_worker.erl  |  2 +-
 src/couch_replicator/src/couch_replicator_docs.erl |  2 +-
 .../src/couch_replicator_httpc.erl                 |  1 +
 .../src/couch_replicator_scheduler.erl             |  2 +-
 .../src/couch_replicator_utils.erl                 |  6 ++--
 .../src/couch_replicator_worker.erl                |  2 ++
 8 files changed, 15 insertions(+), 45 deletions(-)

diff --git a/src/couch_replicator/src/couch_replicator_api_wrap.erl 
b/src/couch_replicator/src/couch_replicator_api_wrap.erl
index 7d34ff053..0b8f84ad3 100644
--- a/src/couch_replicator/src/couch_replicator_api_wrap.erl
+++ b/src/couch_replicator/src/couch_replicator_api_wrap.erl
@@ -206,6 +206,7 @@ get_missing_revs(#httpdb{} = Db, IdRevs) ->
         end
     ).
 
+-spec open_doc_revs(#httpdb{}, binary(), list(), list(), function(), any()) -> 
no_return().
 open_doc_revs(#httpdb{retries = 0} = HttpDb, Id, Revs, Options, _Fun, _Acc) ->
     Path = encode_doc_id(Id),
     QS = options_to_query_args(HttpDb, Path, [revs, {open_revs, Revs} | 
Options]),
@@ -451,11 +452,11 @@ update_docs(#httpdb{} = HttpDb, DocList, Options, 
UpdateType) ->
         ],
         fun
             (201, _, Results) when is_list(Results) ->
-                {ok, bulk_results_to_errors(DocList, Results, remote)};
+                {ok, bulk_results_to_errors(Results)};
             (413, _, _) ->
                 {error, request_body_too_large};
             (417, _, Results) when is_list(Results) ->
-                {ok, bulk_results_to_errors(DocList, Results, remote)};
+                {ok, bulk_results_to_errors(Results)};
             (ErrCode, _, ErrMsg) when is_integer(ErrCode) ->
                 {error, {bulk_docs_failed, ErrCode, ErrMsg}}
         end
@@ -898,39 +899,7 @@ json_to_doc_info({Props}) ->
             }
     end.
 
-bulk_results_to_errors(Docs, {ok, Results}, interactive_edit) ->
-    lists:reverse(
-        lists:foldl(
-            fun
-                ({_, {ok, _}}, Acc) ->
-                    Acc;
-                ({#doc{id = Id, revs = {Pos, [RevId | _]}}, Error}, Acc) ->
-                    {_, Error, Reason} = couch_httpd:error_info(Error),
-                    [
-                        {[
-                            {id, Id},
-                            {rev, rev_to_str({Pos, RevId})},
-                            {error, Error},
-                            {reason, Reason}
-                        ]}
-                        | Acc
-                    ]
-            end,
-            [],
-            lists:zip(Docs, Results)
-        )
-    );
-bulk_results_to_errors(Docs, {ok, Results}, replicated_changes) ->
-    bulk_results_to_errors(Docs, {aborted, Results}, interactive_edit);
-bulk_results_to_errors(_Docs, {aborted, Results}, interactive_edit) ->
-    lists:map(
-        fun({{Id, Rev}, Err}) ->
-            {_, Error, Reason} = couch_httpd:error_info(Err),
-            {[{id, Id}, {rev, rev_to_str(Rev)}, {error, Error}, {reason, 
Reason}]}
-        end,
-        Results
-    );
-bulk_results_to_errors(_Docs, Results, remote) ->
+bulk_results_to_errors(Results) ->
     lists:reverse(
         lists:foldl(
             fun({Props}, Acc) ->
diff --git a/src/couch_replicator/src/couch_replicator_auth_session.erl 
b/src/couch_replicator/src/couch_replicator_auth_session.erl
index 643738ca3..392f954ab 100644
--- a/src/couch_replicator/src/couch_replicator_auth_session.erl
+++ b/src/couch_replicator/src/couch_replicator_auth_session.erl
@@ -207,9 +207,7 @@ init_state(#httpdb{} = HttpDb) ->
                     {error, Error}
             end;
         {error, missing_credentials} ->
-            ignore;
-        {error, Error} ->
-            {error, Error}
+            ignore
     end.
 
 -spec extract_creds(#httpdb{}) ->
@@ -428,7 +426,7 @@ parse_max_age(CaseInsKVs) ->
     end.
 
 -spec maybe_update_cookie(headers(), #state{}) ->
-    {ok, string()} | {error, term()}.
+    {ok, #state{}} | {error, term()}.
 maybe_update_cookie(ResponseHeaders, State) ->
     case parse_cookie(ResponseHeaders) of
         {ok, MaxAge, Cookie} ->
diff --git a/src/couch_replicator/src/couch_replicator_doc_processor_worker.erl 
b/src/couch_replicator/src/couch_replicator_doc_processor_worker.erl
index 5d971151b..22c5f8584 100644
--- a/src/couch_replicator/src/couch_replicator_doc_processor_worker.erl
+++ b/src/couch_replicator/src/couch_replicator_doc_processor_worker.erl
@@ -38,7 +38,7 @@
 % ?WORKER_TIMEOUT_MSEC timeout period.A timeout is considered a
 %`temporary_error`. Result will be sent as the `Reason` in the {'DOWN',...}
 % message.
--spec spawn_worker(db_doc_id(), #rep{}, seconds(), reference()) -> pid().
+-spec spawn_worker(db_doc_id(), #rep{}, seconds(), reference()) -> pid() | 
no_return().
 spawn_worker(Id, Rep, WaitSec, WRef) ->
     {Pid, _Ref} = spawn_monitor(fun() ->
         worker_fun(Id, Rep, WaitSec, WRef)
diff --git a/src/couch_replicator/src/couch_replicator_docs.erl 
b/src/couch_replicator/src/couch_replicator_docs.erl
index 270ec23be..7bdf00bf9 100644
--- a/src/couch_replicator/src/couch_replicator_docs.erl
+++ b/src/couch_replicator/src/couch_replicator_docs.erl
@@ -396,7 +396,7 @@ rep_user_ctx({RepDoc}) ->
             }
     end.
 
--spec parse_rep_db({[_]} | binary(), binary(), [_]) -> #httpd{} | binary().
+-spec parse_rep_db({[_]} | binary(), [_] | binary(), [_]) -> #httpdb{} | 
no_return().
 parse_rep_db({Props}, Proxy, Options) ->
     ProxyParams = parse_proxy_params(Proxy),
     ProxyURL =
diff --git a/src/couch_replicator/src/couch_replicator_httpc.erl 
b/src/couch_replicator/src/couch_replicator_httpc.erl
index 811c9dd1d..c6f22468d 100644
--- a/src/couch_replicator/src/couch_replicator_httpc.erl
+++ b/src/couch_replicator/src/couch_replicator_httpc.erl
@@ -322,6 +322,7 @@ discard_message(ReqId, Worker, Count) ->
         exit({timeout, ibrowse_stream_cleanup})
     end.
 
+-spec maybe_retry(any(), pid(), #httpdb{}, list()) -> no_return().
 maybe_retry(Error, Worker, #httpdb{retries = 0} = HttpDb, Params) ->
     report_error(Worker, HttpDb, Params, {error, Error});
 maybe_retry(
diff --git a/src/couch_replicator/src/couch_replicator_scheduler.erl 
b/src/couch_replicator/src/couch_replicator_scheduler.erl
index f544865af..d02256807 100644
--- a/src/couch_replicator/src/couch_replicator_scheduler.erl
+++ b/src/couch_replicator/src/couch_replicator_scheduler.erl
@@ -809,7 +809,7 @@ ejson_url(#httpdb{} = Httpdb) ->
 ejson_url(DbName) when is_binary(DbName) ->
     DbName.
 
--spec job_ejson(#job{}) -> {[_ | _]}.
+-spec job_ejson(#job{}) -> {[_ | _]} | no_return().
 job_ejson(Job) ->
     Rep = Job#job.rep,
     Source = ejson_url(Rep#rep.source),
diff --git a/src/couch_replicator/src/couch_replicator_utils.erl 
b/src/couch_replicator/src/couch_replicator_utils.erl
index b2bc34078..c9cfac62f 100644
--- a/src/couch_replicator/src/couch_replicator_utils.erl
+++ b/src/couch_replicator/src/couch_replicator_utils.erl
@@ -165,7 +165,7 @@ normalize_rep(#rep{} = Rep) ->
         db_name = Rep#rep.db_name
     }.
 
--spec ejson_state_info(binary() | nil) -> binary() | null.
+-spec ejson_state_info([_] | binary() | nil) -> tuple() | null.
 ejson_state_info(nil) ->
     null;
 ejson_state_info(Info) when is_binary(Info) ->
@@ -198,12 +198,12 @@ get_basic_auth_creds(#httpdb{auth_props = AuthProps}) ->
             {undefined, undefined}
     end.
 
--spec remove_basic_auth_creds(#httpd{}) -> #httpdb{}.
+-spec remove_basic_auth_creds(#httpdb{}) -> #httpdb{}.
 remove_basic_auth_creds(#httpdb{auth_props = Props} = HttpDb) ->
     Props1 = lists:keydelete(<<"basic">>, 1, Props),
     HttpDb#httpdb{auth_props = Props1}.
 
--spec set_basic_auth_creds(string(), string(), #httpd{}) -> #httpdb{}.
+-spec set_basic_auth_creds(string(), string(), #httpdb{}) -> #httpdb{}.
 set_basic_auth_creds(undefined, undefined, #httpdb{} = HttpDb) ->
     HttpDb;
 set_basic_auth_creds(User, Pass, #httpdb{} = HttpDb) when
diff --git a/src/couch_replicator/src/couch_replicator_worker.erl 
b/src/couch_replicator/src/couch_replicator_worker.erl
index 233de6dd3..8826bb559 100644
--- a/src/couch_replicator/src/couch_replicator_worker.erl
+++ b/src/couch_replicator/src/couch_replicator_worker.erl
@@ -256,6 +256,7 @@ remote_process_batch([{Id, Revs, PAs} | Rest], Parent) ->
     ),
     remote_process_batch(Rest, Parent).
 
+-spec spawn_doc_reader(#httpdb{}, #httpdb{}, {list(), list(), list()}) -> 
no_return().
 spawn_doc_reader(Source, Target, FetchParams) ->
     Parent = self(),
     spawn_link(fun() ->
@@ -264,6 +265,7 @@ spawn_doc_reader(Source, Target, FetchParams) ->
         )
     end).
 
+-spec fetch_doc(#httpd{}, {list(), list(), list()}, function(), any()) -> 
no_return().
 fetch_doc(Source, {Id, Revs, PAs}, DocHandler, Acc) ->
     try
         couch_replicator_api_wrap:open_doc_revs(

Reply via email to