anchor.diff:      end.
   
   open_rep_doc(DbName, DocId) ->
  -    {ok, Db} = couch_db:open_int(DbName, [?CTX, sys_db]),
  -    try
  -        couch_db:open_doc(Db, DocId, [ejson_body])
  -    after
  -        couch_db:close(Db)
  +    case couch_db:open_int(DbName, [?CTX, sys_db]) of
  +        {ok, Db} ->
  +            try
  +                couch_db:open_doc(Db, DocId, [ejson_body])
  +            after
  +                couch_db:close(Db)
  +            end;
  +        Else ->
  +            Else
       end.
   
   save_rep_doc(DbName, Doc) ->
  
positive.code: 
  ensure_rep_ddoc_exists(RepDb, DDocId) ->
      case open_rep_doc(RepDb, DDocId) of
          {not_found, _Reason} ->
              {ok, DDoc} = replication_design_doc(DDocId),
              couch_log:notice("creating replicator ddoc", []),
  
negative.code:             true ->
                  ok;
              false ->
                  try
                      [gen_server:cast(Server, {resume_scan, ShardName})
                          || ShardName <- replicator_shards(DbName)]
                  catch error:database_does_not_exist ->
                      ok
                  end
              end
          end;
          (_, _) -> ok
  