# Buggy code
def add(self, paths: Iterable[str]):
    from dvc.utils.fs import walk_files

    if isinstance(paths, str):
        paths = [paths]

    files = []
    for path in paths:
        if not os.path.isabs(path):
            path = os.path.join(self.root_dir, path)
        if os.path.isdir(path):
            files.extend(walk_files(path))
        else:
            files.append(path)

    for fpath in files:
        # NOTE: this doesn't check gitignore, same as GitPythonBackend.add
        self.repo.stage(relpath(fpath, self.root_dir))


# Traceback (FileNotFoundError)
Adding '.dvc/config.local' to '.dvc/.gitignore'.
Adding '.dvc/tmp' to '.dvc/.gitignore'.
Adding '.dvc/experiments' to '.dvc/.gitignore'.
Adding '.dvc/cache' to '.dvc/.gitignore'.
Check for update is enabled.
assuming default target 'dvc.yaml'.
fetched: [(3,)]
Checking out experiment commit 'e6a4d8123aebe35a19b9e4544e21ac542a10as66'
Patching experiment workspace
Removing '/tmp/tmp8e9_4d6f'
Adding '.dvc/experiments/src/ai/training/.dvc/config.local' to '.dvc/experiments/src/ai/training/.dvc/.gitignore'.
Adding '.dvc/experiments/src/ai/training/.dvc/tmp' to '.dvc/experiments/src/ai/training/.dvc/.gitignore'.
Adding '.dvc/experiments/src/ai/training/.dvc/experiments' to '.dvc/experiments/src/ai/training/.dvc/.gitignore'.
Stashed experiment 'f951c9d' for future execution.
Reproducing experiment revs 'f951c9d'
Checking out experiment commit 'e6a4d8123aebe35a19b9e4544e21ac542a10s166'
Writing '/tmp/tmpmml3mawm/.dvc/config'.
Init local executor in dir '<TemporaryDirectory '/tmp/tmpmml3mawm'>' with baseline 'e6a4d81'.
Writing experiments local config '/tmp/tmpmml3mawm/src/ai/training/.dvc/config.local'
fetched: [(7583,)]
unexpected error - [Errno 2] No such file or directory: '/tmp/tmpmml3mawm/src/ai/training/.dvc/config.local'
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpmml3mawm/src/ai/training/.dvc/config.local'
------------------------------------------------------------
Traceback (most recent call last):
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/main.py", line 90, in main
ret = cmd.run()
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/command/experiments.py", line 469, in run
**self._repro_kwargs,
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/__init__.py", line 988, in run
return run(self.repo, *args, **kwargs)
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/__init__.py", line 60, in wrapper
return f(repo, *args, **kwargs)
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/run.py", line 62, in run
target=target, params=params, **kwargs
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/__init__.py", line 418, in reproduce_one
results = self.reproduce([stash_rev], keep_stash=False)
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/__init__.py", line 38, in wrapper
return f(exp, *args, **kwargs)
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/__init__.py", line 593, in reproduce
checkpoint_reset=checkpoint_reset,
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/executor.py", line 116, in __init__
self._config(cache_dir)
File "/home/elena/anaconda3/envs/myenv/lib/python3.6/site-packages/dvc/repo/experiments/executor.py", line 127, in _config
with open(local_config, "w") as fobj:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpmml3mawm/src/ai/training/.dvc/config.local'
------------------------------------------------------------
Adding '.dvc/config.local' to '.dvc/.gitignore'.
Adding '.dvc/tmp' to '.dvc/.gitignore'.
Adding '.dvc/experiments' to '.dvc/.gitignore'.
Adding '.dvc/cache' to '.dvc/.gitignore'.
Version info for developers:
DVC version: 1.10.2 (pip)
---------------------------------
Platform: Python 3.6.12 on Linux-5.4.0-48-generic-x86_64-with-debian-buster-sid
Supports: gs, http, https
Cache types: hardlink, symlink
Cache directory: ext4 on /dev/nvme0n1p2
Caches: local
Remotes: local
Workspace directory: ext4 on /dev/nvme0n1p2
Repo: dvc (subdir), git

# Fixed code
def add(self, paths: Iterable[str]):
    from dvc.utils.fs import walk_files

    if isinstance(paths, str):
        paths = [paths]

    files = []
    for path in paths:
        if not os.path.isabs(path) and self._submodules:
            # NOTE: If path is inside a submodule, Dulwich expects the
            # staged paths to be relative to the submodule root (not the
            # parent git repo root). We append path to root_dir here so
            # that the result of relpath(path, root_dir) is actually the
            # path relative to the submodule root.
            path_info = PathInfo(path).relative_to(self.root_dir)
            for sm_path in self._submodules.values():
                if path_info.isin(sm_path):
                    path = os.path.join(self.root_dir, path_info.relative_to(sm_path))
                    break
        if os.path.isdir(path):
            files.extend(walk_files(path))
        else:
            files.append(path)

    for fpath in files:
        # NOTE: this doesn't check gitignore, same as GitPythonBackend.add
        self.repo.stage(relpath(fpath, self.root_dir))