{"record":{"id":"62a7d71f9ad66465","repo":"pypa/pip","slug":"file-r-does-not-exist","errorCode":null,"errorMessage":"file '%r' does not exist","messagePattern":"file '%r' does not exist","errorType":"exception","errorClass":"DistlibException","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/distlib/util.py","lineNumber":515,"sourceCode":"\n    def record_as_written(self, path):\n        if self.record:\n            self.files_written.add(path)\n\n    def newer(self, source, target):\n        \"\"\"Tell if the target is newer than the source.\n\n        Returns true if 'source' exists and is more recently modified than\n        'target', or if 'source' exists and 'target' doesn't.\n\n        Returns false if both exist and 'target' is the same age or younger\n        than 'source'. Raise PackagingFileError if 'source' does not exist.\n\n        Note that this test is not very accurate: files created in the same\n        second will have the same \"age\".\n        \"\"\"\n        if not os.path.exists(source):\n            raise DistlibException(\"file '%r' does not exist\" % os.path.abspath(source))\n        if not os.path.exists(target):\n            return True\n\n        return os.stat(source).st_mtime > os.stat(target).st_mtime\n\n    def copy_file(self, infile, outfile, check=True):\n        \"\"\"Copy a file respecting dry-run and force flags.\n        \"\"\"\n        self.ensure_dir(os.path.dirname(outfile))\n        logger.info('Copying %s to %s', infile, outfile)\n        if not self.dry_run:\n            msg = None\n            if check:\n                if os.path.islink(outfile):\n                    msg = '%s is a symlink' % outfile\n                elif os.path.exists(outfile) and not os.path.isfile(outfile):\n                    msg = '%s is a non-regular file' % outfile\n            if msg:","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/distlib/util.py#L497-L533","documentation":"Raised as DistlibException by FileOperator.newer when the source file passed to it does not exist on disk. newer() compares mtimes of source and target to decide whether to copy; if the source is missing it cannot proceed. Note the message uses an extra %r inside already-quoted string, so the absolute path appears with repr-style quotes (a minor formatting quirk in the vendored code).","triggerScenarios":"Calling FileOperator().newer('/missing/src.txt', '/dest/src.txt') when /missing/src.txt does not exist; installation/unarchive flows where the source path was computed but not yet materialized; race where source is removed between scheduling and the newer() call.","commonSituations":"Broken install records pointing at files deleted by another tool; build pipelines that assume an earlier step produced a file that actually failed; typo in source path.","solutions":["Check os.path.exists(source) before calling newer().","Verify the upstream step that should create the source file actually ran.","Wrap the call in try/except DistlibException and log/skip with context."],"exampleFix":"# before\nif fileop.newer(src, dst):\n    ...\n# after\nif os.path.exists(src) and fileop.newer(src, dst):\n    ...","handlingStrategy":"validation","validationCode":"def newer_safe(fileop, source, target):\n    if not os.path.exists(source):\n        raise FileNotFoundError(source)\n    return fileop.newer(source, target)","typeGuard":"def file_exists(path: str) -> bool:\n    return isinstance(path, str) and os.path.exists(path)","tryCatchPattern":"from distlib.util import DistlibException\ntry:\n    fileop.newer(src, dst)\nexcept DistlibException as e:\n    if 'does not exist' in str(e):\n        log.warning('source missing: %s', src)","preventionTips":["Check os.path.exists(source) before newer().","Verify upstream build steps produced the file."],"tags":["filesystem","distlib","fileoperator","installation","missing-file"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}