{"record":{"id":"ebc67b9e62b6ac20","repo":"ungoogled-software/ungoogled-chromium","slug":"fileexistserror","errorCode":null,"errorMessage":"FileExistsError","messagePattern":"FileExistsError","errorType":"exception","errorClass":"FileExistsError","httpStatus":null,"severity":"error","filePath":"utils/domain_substitution.py","lineNumber":205,"sourceCode":"    regex_path is a pathlib.Path to domain_regex.list\n    files_path is a pathlib.Path to domain_substitution.list\n    source_tree is a pathlib.Path to the source tree.\n    domainsub_cache is a pathlib.Path to the domain substitution cache.\n\n    Raises NotADirectoryError if the patches directory is not a directory or does not exist\n    Raises FileNotFoundError if the source tree or required directory does not exist.\n    Raises FileExistsError if the domain substitution cache already exists.\n    Raises ValueError if an entry in the domain substitution list contains the file index\n        hash delimiter.\n    \"\"\"\n    if not source_tree.exists():\n        raise FileNotFoundError(source_tree)\n    if not regex_path.exists():\n        raise FileNotFoundError(regex_path)\n    if not files_path.exists():\n        raise FileNotFoundError(files_path)\n    if domainsub_cache and domainsub_cache.exists():\n        raise FileExistsError(domainsub_cache)\n    resolved_tree = source_tree.resolve()\n    regex_pairs = DomainRegexList(regex_path).regex_pairs\n    fileindex_content = io.BytesIO()\n    with tarfile.open(str(domainsub_cache), f'w:{domainsub_cache.suffix[1:]}',\n                      compresslevel=1) if domainsub_cache else open(\n                          os.devnull, 'w', encoding=ENCODING) as cache_tar:\n        for relative_path in filter(len, files_path.read_text().splitlines()):\n            if _INDEX_HASH_DELIMITER in relative_path:\n                if domainsub_cache:\n                    # Cache tar will be incomplete; remove it for convenience\n                    cache_tar.close()\n                    domainsub_cache.unlink()\n                raise ValueError(f'Path \"{relative_path}\" contains '\n                                 f'the file index hash delimiter \"{_INDEX_HASH_DELIMITER}\"')\n            path = resolved_tree / relative_path\n            if not path.exists():\n                get_logger().warning('Skipping non-existent path: %s', path)\n                continue","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/ungoogled-software/ungoogled-chromium/blob/f85e84a480e2e17c103de7013de94320f9a2ba39/utils/domain_substitution.py#L187-L223","documentation":"apply_substitution() raises FileExistsError(domainsub_cache) when a cache archive path is supplied and a file already exists at that location, to avoid overwriting an existing domain-substitution cache tar.","triggerScenarios":"Calling apply_substitution() with a non-None domainsub_cache whose path .exists() — e.g. re-running apply after a previous run created the cache, or a stale cache file left behind.","commonSituations":"Re-running substitution after an aborted/previous run; resuming a pipeline where the cache wasn't cleaned; reusing the same cache filename for multiple source trees.","solutions":["Delete the existing cache file before re-running apply_substitution()","Pass a new/unique cache path (or domainsub_cache=None to skip caching)","Only pass domainsub_cache when starting a fresh substitution"],"exampleFix":"// before\ncache = Path('domsub_cache.tar.gz')\napply_substitution(tree, regexes, files, domainsub_cache=cache)\n// after\ncache = Path('domsub_cache.tar.gz')\nif cache.exists():\n    cache.unlink()\napply_substitution(tree, regexes, files, domainsub_cache=cache)","handlingStrategy":"validation","validationCode":"cache = Path('domsub_cache.tar.gz').resolve()\nif cache.exists():\n    cache.unlink()  # or choose a new unique name","typeGuard":null,"tryCatchPattern":"try:\n    apply_substitution(tree, regexes, files, domainsub_cache=cache)\nexcept FileExistsError:\n    cache.unlink()\n    apply_substitution(tree, regexes, files, domainsub_cache=cache)","preventionTips":["Clean stale cache files at the start of a substitution run","Use unique cache names per source tree/run","Only pass domainsub_cache for fresh runs"],"tags":["filesystem","file-exists","cache","substitution"],"backgroundTag":"output-directory-already-exists","analyzedSha":"f85e84a480e2e17c103de7013de94320f9a2ba39","analyzedAt":"2026-08-29T10:07:17.606Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}