{"record":{"id":"bdf13bef89ec9e5c","repo":"iflytek/astron-agent","slug":"invite-add-team-user-failed","errorCode":"INVITE_ADD_TEAM_USER_FAILED","errorMessage":"INVITE_ADD_TEAM_USER_FAILED","messagePattern":"INVITE_ADD_TEAM_USER_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/EnterpriseBizServiceImpl.java","lineNumber":83,"sourceCode":"        }\n        if (enterpriseService.checkExistByName(enterpriseAddDTO.getName(), null)) {\n            return ApiResult.error(ResponseEnum.ENTERPRISE_NAME_EXISTS);\n        }\n        if (enterpriseService.checkExistByUid(uid)) {\n            return ApiResult.error(ResponseEnum.ENTERPRISE_USER_ALREADY_CREATED_ENTERPRISE);\n        }\n        // Save team data\n        Enterprise enterprise = new Enterprise();\n        enterprise.setName(enterpriseAddDTO.getName());\n        enterprise.setAvatarUrl(enterpriseAddDTO.getAvatarUrl());\n        enterprise.setUid(uid);\n        enterprise.setOrgId(IdWorker.getId());\n        enterprise.setServiceType(enterpriseResult.getServiceType().getCode());\n        enterprise.setExpireTime(enterpriseResult.getEndTime());\n        if (enterpriseService.save(enterprise)) {\n            // Creator becomes enterprise super admin by default\n            if (!enterpriseUserService.addEnterpriseUser(enterprise.getId(), enterprise.getUid(), EnterpriseRoleEnum.OFFICER)) {\n                throw new BusinessException(ResponseEnum.INVITE_ADD_TEAM_USER_FAILED);\n            }\n            return ApiResult.success(enterprise.getId());\n        }\n        return ApiResult.error(ResponseEnum.ENTERPRISE_CREATE_FAILED);\n    }\n\n    /**\n     * Update team name\n     *\n     * @param name\n     * @return\n     */\n    @Override\n    @Transactional\n    public ApiResult<String> updateName(String name) {\n        Long enterpriseId = EnterpriseInfoUtil.getEnterpriseId();\n        if (enterpriseService.checkExistByName(name, enterpriseId)) {\n            return ApiResult.error(ResponseEnum.ENTERPRISE_NAME_EXISTS);","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/space/impl/EnterpriseBizServiceImpl.java#L65-L101","documentation":"INVITE_ADD_TEAM_USER_FAILED is thrown during enterprise creation when the enterprise record is saved but adding the creator as the enterprise super admin (EnterpriseRoleEnum.OFFICER) fails. The enterprise would otherwise be created without any owner, so the operation is aborted with this error.","triggerScenarios":"enterpriseUserService.addEnterpriseUser(enterpriseId, creatorUid, OFFICER) returns false right after a successful enterpriseService.save — typically a duplicate membership row or a DB write failure.","commonSituations":"Retry after partial failure leaving an orphan enterprise-user row; user account deleted concurrently; DB constraint or connection errors on the enterprise-user table.","solutions":["Check for an existing enterprise-user row for this user and clean orphans","Retry enterprise creation with a fresh org/enterprise ID","Inspect enterpriseUserService logs and the enterprise-user table for the write failure","Wrap save + addEnterpriseUser in one transaction so partial state can't persist"],"exampleFix":"// before\nenterpriseService.save(enterprise);\nif (!enterpriseUserService.addEnterpriseUser(id, uid, OFFICER)) { throw ... }\n// after\n@Transactional\nif (enterpriseService.save(enterprise)\n        && enterpriseUserService.addEnterpriseUser(enterprise.getId(), enterprise.getUid(), EnterpriseRoleEnum.OFFICER)) {\n    return ApiResult.success(enterprise.getId());\n}","handlingStrategy":"try-catch","validationCode":"if (enterpriseUserService.getEnterpriseUser(enterpriseId, creatorUid) != null) { /* already officer; skip add */ }","typeGuard":null,"tryCatchPattern":"try { enterpriseService.create(...); } catch (BusinessException e) { if (\"INVITE_ADD_TEAM_USER_FAILED\".equals(e.getMessage())) { /* clean up orphan enterprise record, then retry */ } }","preventionTips":["Save enterprise and add owner in a single transaction","Clean up partial state on failure (compensating delete of the enterprise)","Check for pre-existing membership rows before insert"],"tags":["enterprise","membership","transaction"],"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"}