{"record":{"id":"d9ca6af61c9fb6ef","repo":"iflytek/astron-agent","slug":"space-user-add-failed-d9ca6a","errorCode":"SPACE_USER_ADD_FAILED","errorMessage":"SPACE_USER_ADD_FAILED","messagePattern":"SPACE_USER_ADD_FAILED","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/space/impl/InviteRecordBizServiceImpl.java","lineNumber":270,"sourceCode":"        if (responseMsg != null) {\n            return responseMsg;\n        }\n        // Update invitation record\n        inviteRecord.setStatus(InviteRecordStatusEnum.ACCEPT.getCode());\n        if (!inviteRecordService.updateById(inviteRecord)) {\n            return ApiResult.error(ResponseEnum.OPERATION_FAILED);\n        }\n        // For enterprise invitation, add enterprise user\n        if (InviteRecordTypeEnum.ENTERPRISE.getCode().equals(inviteRecord.getType())) {\n            if (!enterpriseUserService.addEnterpriseUser(inviteRecord.getEnterpriseId(), inviteRecord.getInviteeUid(),\n                    Objects.equals(InviteRecordRoleEnum.ADMIN.getCode(), inviteRecord.getRole()) ? EnterpriseRoleEnum.GOVERNOR : EnterpriseRoleEnum.STAFF)) {\n                throw new BusinessException(ResponseEnum.INVITE_ADD_TEAM_USER_FAILED);\n            }\n            // Add space user\n        } else if (InviteRecordTypeEnum.SPACE.getCode().equals(inviteRecord.getType())) {\n            if (!spaceUserService.addSpaceUser(inviteRecord.getSpaceId(), inviteRecord.getInviteeUid(),\n                    Objects.equals(InviteRecordRoleEnum.ADMIN.getCode(), inviteRecord.getRole()) ? SpaceRoleEnum.ADMIN : SpaceRoleEnum.MEMBER)) {\n                throw new BusinessException(ResponseEnum.SPACE_USER_ADD_FAILED);\n            }\n            Space space = spaceService.getSpaceById(inviteRecord.getSpaceId());\n            // For enterprise space invitation, if not joined team, add user\n            if (space.getEnterpriseId() != null) {\n                if (!enterpriseUserService.addEnterpriseUser(space.getEnterpriseId(), inviteRecord.getInviteeUid(),\n                        Objects.equals(InviteRecordRoleEnum.ADMIN.getCode(), inviteRecord.getRole()) ? EnterpriseRoleEnum.GOVERNOR : EnterpriseRoleEnum.STAFF)) {\n                    throw new BusinessException(ResponseEnum.INVITE_ADD_TEAM_USER_FAILED);\n                }\n            }\n        } else {\n            throw new BusinessException(ResponseEnum.INVITE_UNSUPPORTED_TYPE);\n        }\n        return ApiResult.success();\n    }\n\n    /**\n     * Decline invitation\n     *","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/space/impl/InviteRecordBizServiceImpl.java#L252-L288","documentation":"SPACE_USER_ADD_FAILED is thrown when accepting a SPACE-type invitation and adding the invitee to the space (ADMIN or MEMBER per the invite role) fails via spaceUserService.addSpaceUser returning false.","triggerScenarios":"acceptInvite on a SPACE invitation where spaceUserService.addSpaceUser(spaceId, inviteeUid, role) returns false — already a member, space deleted, or the membership write failed.","commonSituations":"Double-clicking accept on an invite; the space was deleted while the invite was pending; DB constraint violations on the space-user table.","solutions":["Make acceptance idempotent: if the user is already in the space, skip the add and continue","Verify the space exists and is active before accepting","Check spaceUserService logs/DB for the root write failure"],"exampleFix":"// before\nif (!spaceUserService.addSpaceUser(spaceId, uid, role)) {\n    throw new BusinessException(ResponseEnum.SPACE_USER_ADD_FAILED);\n}\n// after\nif (!spaceUserService.isSpaceUser(spaceId, uid)\n        && !spaceUserService.addSpaceUser(spaceId, uid, role)) {\n    throw new BusinessException(ResponseEnum.SPACE_USER_ADD_FAILED);\n}","handlingStrategy":"validation","validationCode":"if (spaceUserService.isSpaceUser(inviteRecord.getSpaceId(), inviteRecord.getInviteeUid())) { /* skip add, continue to enterprise check */ }","typeGuard":null,"tryCatchPattern":"try { acceptInvite(inviteId); } catch (BusinessException e) { if (\"SPACE_USER_ADD_FAILED\".equals(e.getMessage())) { /* check if already member; verify space exists */ } }","preventionTips":["Prevent duplicate space membership inserts","Expire or deactivate invites when the target space is deleted","Log the underlying DB error from addSpaceUser for triage"],"tags":["invite","space","membership"],"backgroundTag":"database-write-failed","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}