code: def _try_clone_candidates(
      *,
      destds: Dataset,
      candidate_sources: List,
      clone_opts: List,
      dest_path_existed: bool,
  ) -> Tuple:
      """Iterate over candidate URLs and attempt a clone
  
      Parameters
      ----------
      destds: Dataset
        The target dataset the clone should materialize at.
      candidate_sources: list
        Each value is a dict with properties, as returned by
        `_generate_candidate_clone_sources()`
      clone_opts: list
        Options to be passed on to `_try_clone_candidate()`
      dest_path_existed: bool
        Flag whether the target path existed before attempting a clone.
  
      Returns
      -------
      (dict or None, dict, dict or None)
        The candidate record of the last clone attempt,
        a mapping of candidate URLs to potential error messages they yielded,
        and either a dict with properties of a result that should be yielded
        before an immediate return, or None, if the processing can continue
      """
      log_progress(
          lgr.info,
          "cloneds",
          "Attempting a clone into %s",
          destds.path,
          unit=" candidates",
          label="Cloning",
          total=len(candidate_sources),
      )
      error_msgs = (
          dict()
      )  # accumulate all error messages formatted per each url
      for cand in candidate_sources:
          log_progress(
              lgr.info,
              "cloneds",
              "Attempting to clone from %s to %s",
              cand["giturl"],
              destds.path,
              update=1,
              increment=True,
          )
  
          tried_url, error, fatal = _try_clone_candidate(
              destds=destds,
              cand=cand,
              clone_opts=clone_opts,
          )
  
          if error is not None:
              lgr.debug(
                  "Failed to clone from URL: %s (%s)", tried_url, error
              )
  
              error_msgs[tried_url] = error
  
              # ready playing field for the next attempt
              if destds.pathobj.exists():
                  lgr.debug(
                      "Wiping out unsuccessful clone attempt at: %s",
                      destds.path,
                  )
                  # We must not just rmtree since it might be curdir etc
                  # we should remove all files/directories under it
                  # TODO stringification can be removed once patlib compatible
                  # or if PY35 is no longer supported
                  rmtree(destds.path, children_only=dest_path_existed)
  
          if fatal:
              # cancel progress bar
              log_progress(
                  lgr.info,
                  "cloneds",
                  "Completed clone attempts for %s",
                  destds,
              )
              return cand, error_msgs, fatal
  
          if error is None:
              # do not bother with other sources if succeeded
              break
  
      log_progress(
          lgr.info, "cloneds", "Completed clone attempts for %s", destds
      )
      return cand, error_msgs, None
  
imports: import logging
  import re
  from os.path import expanduser
  from pathlib import Path
  from typing import Dict, List, Tuple
  from urllib.parse import unquote
  from datalad.cmd import CommandError, GitWitlessRunner, StdOutCapture
  from datalad.config import ConfigManager
  from datalad.distributed.ora_remote import LocalIO, RIARemoteError, SSHRemoteIO
  from datalad.distribution.dataset import Dataset
  from datalad.distribution.utils import _get_flexible_source_candidates
  from datalad.dochelpers import single_or_plural
  from datalad.log import log_progress
  from datalad.runner.exception import CommandError
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.exceptions import CapturedException, DownloadError
  from datalad.support.gitrepo import GitRepo
  from datalad.support.network import RI, SSHRI, URL, DataLadRI, download_url, get_local_file_url, is_url
  from datalad.support.strings import get_replacement_dict
  from datalad.utils import Path, PurePosixPath, ensure_bool, ensure_list, make_tempfile, rmtree
label_desc: Use image node_id 10 for calling a global function with example usage: _try_clone_candidates() and returns: cand,  error_msgs,  None, cand,  error_msgs,  fatal