{"record":{"id":"86cfef4b41715e5d","repo":"HumanSignal/label-studio","slug":"path-what-already-exists-use-force-option","errorCode":null,"errorMessage":"{path} {what} already exists. Use \"--force\" option to recreate it.","messagePattern":"(.+?) (.+?) already exists\\. Use \"--force\" option to recreate it\\.","errorType":"console","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"label_studio/io_storages/filesystem.py","lineNumber":82,"sourceCode":"        self.data.pop(int(key), None)\n        self._save()\n\n    def remove_all(self, ids=None):\n        if ids is None:\n            self.data = {}\n        else:\n            [self.data.pop(i, None) for i in ids]\n        self._save()\n\n    def empty(self):\n        return len(self.data) == 0\n\n    def sync(self):\n        pass\n\n\ndef already_exists_error(what, path):\n    raise RuntimeError(\n        '{path} {what} already exists. Use \"--force\" option to recreate it.'.format(path=path, what=what)\n    )\n\n\nclass DirJSONsStorage(BaseStorage):\n    description = 'Directory with JSON task files'\n\n    def __init__(self, **kwargs):\n        super(DirJSONsStorage, self).__init__(**kwargs)\n        os.makedirs(self.path, exist_ok=True)\n        self.cache = {}\n\n    @property\n    def readable_path(self):\n        return self.path\n\n    def get(self, id):\n        if id in self.cache:","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/io_storages/filesystem.py#L64-L100","documentation":"already_exists_error is a helper that raises RuntimeError when a filesystem resource (project dir, storage dir) the CLI/setup tries to create already exists on disk. Label Studio refuses to clobber existing directories unless explicitly told with --force.","triggerScenarios":"Running the filesystem storage creation/setup command a second time against the same path, or a prior run partially created the directory, so the target {path} already exists on disk.","commonSituations":"Re-running a scripted initialization after a first run succeeded; switching data directories but reusing an old project name; Docker volume remounts leaving stale directories.","solutions":["Pass the --force option to recreate/overwrite the existing path if its contents can be discarded","Use a new unique path/name for the new storage or project","Manually move/rename the existing directory before re-running","If the directory is stale from a failed prior run, delete it first"],"exampleFix":"# before\nlabel-studio init ./myproject  # second run: already exists\n# after\nlabel-studio init ./myproject --force","handlingStrategy":"try-catch","validationCode":"import os\ndef path_is_free(path):\n    return not os.path.exists(path)","typeGuard":"def is_new_dir(path):\n    import os\n    return os.path.isdir(path) is False","tryCatchPattern":"try:\n    create_storage(path)\nexcept RuntimeError as e:\n    if 'already exists' in str(e) and '--force' not in sys.argv:\n        logger.error('%s — rerun with --force or pick a new path', e)","preventionTips":["Check os.path.exists() before scripted creation","Use unique, timestamped paths for automated runs","Clean up partially created directories after failed runs","Only use --force when the existing contents are disposable"],"tags":["filesystem","cli","conflict"],"backgroundTag":"resource-already-exists","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}