code: def collect_files(
      repo: "Repo",
      onerror: Optional[Callable[[str, Exception], None]] = None,
  ):
      """Collects all of the stages present in the DVC repo.
  
      Args:
          onerror (optional): callable that will be called with two args:
              the filepath whose collection failed and the exc instance.
              It can report the error to continue with the collection
              (and, skip failed ones), or raise the exception to abort
              the collection.
      """
      from dvc.dvcfile import is_valid_filename
      from dvc.exceptions import DvcException
      from dvc.utils import relpath
  
      scm = repo.scm
      fs = repo.fs
      sep = fs.sep
      outs: Set[str] = set()
  
      is_local_fs = isinstance(fs, LocalFileSystem)
  
      def is_ignored(path):
          # apply only for the local fs
          return is_local_fs and scm.is_ignored(path)
  
      def is_dvcfile_and_not_ignored(root, file):
          return is_valid_filename(file) and not is_ignored(
              f"{root}{sep}{file}"
          )
  
      def is_out_or_ignored(root, directory):
          dir_path = f"{root}{sep}{directory}"
          # trailing slash needed to check if a directory is gitignored
          return dir_path in outs or is_ignored(f"{dir_path}{sep}")
  
      walk_iter = repo.dvcignore.walk(
          fs, repo.root_dir, followlinks=False
      )
      if logger.isEnabledFor(logging.TRACE):  # type: ignore[attr-defined]
          walk_iter = log_walk(walk_iter)
  
      for root, dirs, files in walk_iter:
          dvcfile_filter = partial(is_dvcfile_and_not_ignored, root)
          for file in filter(dvcfile_filter, files):
              file_path = fs.join(root, file)
              try:
                  index = Index.from_file(repo, file_path)
              except DvcException as exc:
                  if onerror:
                      onerror(relpath(file_path), exc)
                      continue
                  raise
  
              outs.update(
                  out.fspath
                  for stage in index.stages
                  for out in stage.outs
                  if out.protocol == "local"
              )
              yield file_path, index
          dirs[:] = [d for d in dirs if not is_out_or_ignored(root, d)]
  
imports: import logging
  import time
  from collections import defaultdict
  from functools import partial
  from itertools import chain
  from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, Iterator, List, NamedTuple, Optional, Set, Tuple, Union
  from funcy.debug import format_time
  from dvc.dependency import ParamsDependency
  from dvc.fs import LocalFileSystem
  from dvc.fs.callbacks import DEFAULT_CALLBACK
  from dvc.log import logger
  from dvc.utils.objects import cached_property
label_desc: Use image node_id 2 for calling a global function with example usage: collect_files(repo, onerror) and returns: unknown, unknown, unknown