{"record":{"id":"90fa928f5fd40942","repo":"iflytek/astron-agent","slug":"space-user-add-failed","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/ApplyRecordBizServiceImpl.java","lineNumber":119,"sourceCode":"        ApplyRecord applyRecord = applyRecordService.getById(applyId);\n        if (applyRecord == null) {\n            return ApiResult.error(ResponseEnum.SPACE_APPLICATION_RECORD_NOT_FOUND);\n        }\n        if (!Objects.equals(applyRecord.getSpaceId(), SpaceInfoUtil.getSpaceId())) {\n            return ApiResult.error(ResponseEnum.SPACE_APPLICATION_CURRENT_SPACE_INCONSISTENT);\n        }\n        if (!Objects.equals(applyRecord.getStatus(), ApplyRecord.Status.APPLYING.getCode())) {\n            return ApiResult.error(ResponseEnum.SPACE_APPLICATION_STATUS_INCORRECT);\n        }\n        applyRecord.setStatus(ApplyRecord.Status.APPROVED.getCode());\n        applyRecord.setAuditTime(LocalDateTime.now());\n        applyRecord.setAuditUid(RequestContextUtil.getUID());\n        if (!applyRecordService.updateById(applyRecord)) {\n            return ApiResult.error(ResponseEnum.SPACE_APPLICATION_APPROVAL_FAILED);\n        }\n        // Add space user\n        if (!spaceUserService.addSpaceUser(applyRecord.getSpaceId(), applyRecord.getApplyUid(), SpaceRoleEnum.MEMBER)) {\n            throw new BusinessException(ResponseEnum.SPACE_USER_ADD_FAILED);\n        }\n        return ApiResult.success();\n\n    }\n\n    /**\n     * Reject application to join enterprise space\n     *\n     * @param applyId\n     * @return\n     */\n    @Override\n    @Transactional\n    public ApiResult<String> refuseEnterpriseSpace(Long applyId) {\n        ApplyRecord applyRecord = applyRecordService.getById(applyId);\n        if (applyRecord == null) {\n            return ApiResult.error(ResponseEnum.SPACE_APPLICATION_RECORD_NOT_FOUND);\n        }","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/space/impl/ApplyRecordBizServiceImpl.java#L101-L137","documentation":"SPACE_USER_ADD_FAILED is thrown when approving an enterprise space application succeeds up to updating the apply record, but adding the applicant as a space MEMBER via spaceUserService.addSpaceUser returns false. The approval cannot complete because the membership insert/update failed.","triggerScenarios":"spaceUserService.addSpaceUser(spaceId, applyUid, SpaceRoleEnum.MEMBER) returns false — e.g. the user is already a member, the space no longer exists, or the user record write failed.","commonSituations":"Duplicate approvals racing so the user already exists; the applicant was deleted before approval; the target space was removed mid-flow; DB constraint violations on the membership table.","solutions":["Check whether the user is already a member of the space (idempotent handling)","Verify the space and applicant still exist before approving","Inspect spaceUserService logs/DB errors for the underlying write failure","Make addSpaceUser idempotent so re-approval doesn't fail on existing membership"],"exampleFix":"// before\nif (!spaceUserService.addSpaceUser(spaceId, uid, SpaceRoleEnum.MEMBER)) {\n    throw new BusinessException(ResponseEnum.SPACE_USER_ADD_FAILED);\n}\n// after\nif (!spaceUserService.isSpaceUser(spaceId, uid)) {\n    if (!spaceUserService.addSpaceUser(spaceId, uid, SpaceRoleEnum.MEMBER)) {\n        throw new BusinessException(ResponseEnum.SPACE_USER_ADD_FAILED);\n    }\n}","handlingStrategy":"try-catch","validationCode":"if (spaceUserService.isSpaceUser(spaceId, applyUid)) { return ApiResult.success(); } // already a member","typeGuard":null,"tryCatchPattern":"try { approve(...); } catch (BusinessException e) { if (\"SPACE_USER_ADD_FAILED\".equals(e.getMessage())) { /* check membership state, make operation idempotent, retry */ } }","preventionTips":["Make addSpaceUser idempotent (insert-or-ignore on existing membership)","Run record update and membership add in one transaction","Verify space and applicant exist before approval"],"tags":["space","membership","database"],"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"}