{"record":{"id":"922f73a9546f52ae","repo":"juicedata/juicefs","slug":"file-exists-path","errorCode":null,"errorMessage":"File exists: {path}","messagePattern":"File exists: (.+?)","errorType":"exception","errorClass":"FileExistsError","httpStatus":null,"severity":"error","filePath":"sdk/python/juicefs/juicefs/spec.py","lineNumber":48,"sourceCode":"    \"\"\"\n    A JuiceFS file system.\n    \"\"\"\n    protocol = \"jfs\", \"juicefs\"\n    def __init__(self, name, auto_mkdir=False, **kwargs):\n        if self._cached:\n            return\n        super().__init__(**kwargs)\n        self.auto_mkdir = auto_mkdir\n        self.temppath = kwargs.pop(\"temppath\", \"/tmp\")\n        self.fs = Client(name, **kwargs)\n\n    @property\n    def fsid(self):\n        return \"jfs_\" + self.fs.name\n\n    def makedirs(self, path, exist_ok=False, mode=511):\n        if self.exists(path) and not exist_ok:\n            raise FileExistsError(f\"File exists: {path}\")\n        self.fs.makedirs(self._strip_protocol(path), mode, exist_ok=exist_ok)\n\n    def mkdir(self, path, create_parents=True, mode=0o511):\n        if self.exists(path):\n            raise FileExistsError(f\"File exists: {path}\")\n        if create_parents:\n            self.fs.makedirs(self._strip_protocol(path), mode=mode)\n        else:\n            self.fs.mkdir(self._strip_protocol(path), mode)\n\n    def rmdir(self, path):\n        self.fs.rmdir(self._strip_protocol(path))\n\n    def ls(self, path, detail=False, **kwargs):\n        infos = self.fs.listdir(self._strip_protocol(path), detail)\n        if not detail:\n            return infos\n        stats = []","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/sdk/python/juicefs/juicefs/spec.py#L30-L66","documentation":"Raised by JuiceFSFS.makedirs in fsspec when the target path already exists and exist_ok is False. It mirrors os.makedirs semantics: directory creation is refused to avoid silently reusing an existing path; pass exist_ok=True to tolerate it.","triggerScenarios":"Calling fs.makedirs('/a/b') where the path already exists without exist_ok=True; caching layers racing so exists() returns True; calling makedirs on a path created by a previous run of the script.","commonSituations":"Idempotent setup scripts re-creating directory trees; concurrent workers both calling makedirs; default mode=511 expectation differences.","solutions":["Pass exist_ok=True: fs.makedirs(path, exist_ok=True)","Check fs.exists(path) before calling makedirs","Catch FileExistsError and treat it as success if the dir is expected"],"exampleFix":"// before\nfs.makedirs('/mnt/jfs/checkpoints')\n// after\nfs.makedirs('/mnt/jfs/checkpoints', exist_ok=True)","handlingStrategy":"try-catch","validationCode":"if fs.exists(path) and not exist_ok:\n    return  # or skip creation","typeGuard":null,"tryCatchPattern":"try:\n    fs.makedirs(path)\nexcept FileExistsError:\n    pass  # idempotent create","preventionTips":["Default to exist_ok=True for idempotent setup code","Check fs.exists() before creating shared directory trees"],"tags":["python","fileexistserror","makedirs","idempotency"],"backgroundTag":"file-already-exists","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}