{"record":{"id":"5fd1a23de9403d61","repo":"passbolt/passbolt_api","slug":"the-folder-does-not-exist-foldersshareservice","errorCode":null,"errorMessage":"The folder does not exist.","messagePattern":"The folder does not exist\\.","errorType":"exception","errorClass":"Cake\\Http\\Exception\\NotFoundException","httpStatus":404,"severity":"error","filePath":"plugins/PassboltCe/Folders/src/Service/Folders/FoldersShareService.php","lineNumber":154,"sourceCode":"    }\n\n    /**\n     * Retrieve the folder.\n     *\n     * @param string $folderId The folder identifier to retrieve.\n     * @param \\App\\Utility\\UserAccessControl $uac UserAccessControl updating the resource\n     * @return \\Passbolt\\Folders\\Model\\Entity\\Folder\n     * @throws \\Cake\\Http\\Exception\\NotFoundException If the folder does not exist.\n     */\n    private function getFolder(string $folderId, UserAccessControl $uac): Folder\n    {\n        /** @var \\Passbolt\\Folders\\Model\\Entity\\Folder|null $folder */\n        $folder = $this->foldersTable->findById($folderId)\n            ->find(FolderizableBehavior::FINDER_NAME, user_id: $uac->getId())\n            ->first();\n\n        if (empty($folder)) {\n            throw new NotFoundException(__('The folder does not exist.'));\n        }\n\n        return $folder;\n    }\n\n    /**\n     * Assert if the operator can share the given folder.\n     *\n     * @param \\App\\Utility\\UserAccessControl $uac The operator\n     * @param \\Passbolt\\Folders\\Model\\Entity\\Folder $folder The folder to assert\n     * @return void\n     * @throws \\Cake\\Http\\Exception\\ForbiddenException If the user cannot share the folder\n     */\n    private function assertUserCanShare(UserAccessControl $uac, Folder $folder): void\n    {\n        $userId = $uac->getId();\n        $isAllowed = $this->userHasPermissionService\n            ->check(PermissionsTable::FOLDER_ACO, $folder->id, $userId, Permission::OWNER);","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Folders/src/Service/Folders/FoldersShareService.php#L136-L172","documentation":"Thrown by FoldersShareService::getFolder() when findById() scoped through FolderizableBehavior returns no row for the given folder id and user. Because the finder is user-scoped, this can mean either the folder does not exist or the user has no visibility of it.","triggerScenarios":"Sharing a nonexistent folder id; sharing a folder the current user cannot see (no permission row, or personal folder of another user); id of a deleted folder.","commonSituations":"Share requests built from stale client state; users attempting to share folders that were shared with them but later revoked; automation passing ids of other users' personal folders.","solutions":["Confirm the folder id via GET /folders (as the same user) before sharing.","Ensure the user has at least read permission on the folder being shared.","Check that the id belongs to the correct instance/environment (staging vs prod mixups).","Catch NotFoundException and report 'folder not found or not visible' to the caller."],"exampleFix":"// before\nshare($uac, 'folder-of-another-user', ...); // invisible to $uac\n// after\n$visible = $foldersTable->findById($id)->find(FolderizableBehavior::FINDER_NAME, user_id: $uac->getId())->first();\nif (!$visible) { throw new BadRequestException('Folder not found or not visible'); }","handlingStrategy":"validation","validationCode":"$visible = $foldersTable->findById($folderId)\n  ->find(FolderizableBehavior::FINDER_NAME, user_id: $uac->getId())->first();\nif (!$visible) { throw new InvalidArgumentException('Folder not found or not visible to user'); }","typeGuard":"$isShareable = fn(UserAccessControl $uac, string $id): bool => (bool) $foldersTable->findById($id)->find(FolderizableBehavior::FINDER_NAME, user_id: $uac->getId())->first();","tryCatchPattern":"try { $service->share($uac, $folderId, $changes); } catch (NotFoundException $e) { /* report folder not found/not visible */ }","preventionTips":["Confirm visibility of the folder as the sharing user before calling share","Check permission rows when sharing fails for shared folders","Avoid sharing ids pulled from other users' contexts or environments"],"tags":["not-found","folders","sharing"],"backgroundTag":"entity-not-found","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}