{"record":{"id":"b95f55259a5ad88b","repo":"iflytek/astron-agent","slug":"repo-status-illegal-responseenum","errorCode":"REPO_STATUS_ILLEGAL","errorMessage":"ResponseEnum.REPO_STATUS_ILLEGAL","messagePattern":"ResponseEnum\\.REPO_STATUS_ILLEGAL","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/repo/RepoService.java","lineNumber":894,"sourceCode":"     * @throws BusinessException if repository does not exist, user has no permission, or status\n     *         transition is invalid\n     */\n    @Transactional\n    public void enableRepo(Long id, Integer enabled) {\n        Repo repo = this.getById(id);\n        if (repo == null) {\n            throw new BusinessException(ResponseEnum.REPO_NOT_EXIST);\n        }\n        dataPermissionCheckTool.checkRepoBelong(repo);\n        RepoVO repoVO = new RepoVO();\n        repoVO.setId(id);\n        if ((Objects.equals(repo.getStatus(), ProjectContent.REPO_STATUS_CREATED)\n                || Objects.equals(repo.getStatus(), ProjectContent.REPO_STATUS_PUBLISHED)) && enabled == 0) {\n            repoVO.setOperType(ProjectContent.REPO_STATUS_UNPUBLISHED);\n        } else if (Objects.equals(repo.getStatus(), ProjectContent.REPO_STATUS_UNPUBLISHED) && enabled == 1) {\n            repoVO.setOperType(ProjectContent.REPO_STATUS_PUBLISHED);\n        } else {\n            throw new BusinessException(ResponseEnum.REPO_STATUS_ILLEGAL);\n        }\n        this.updateRepoStatus(repoVO);\n    }\n\n\n    public JSONObject deleteXinghuoDataset(HttpServletRequest request, String id) {\n        Map<String, String> params = new HashMap<>();\n        params.put(\"datasetId\", id);\n\n        Map<String, String> headers = new HashMap<>();\n        String authorization = request.getHeader(\"Authorization\");\n        if (StringUtils.isNotBlank(authorization)) {\n            headers.put(\"Authorization\", authorization);\n        }\n        String response = OkHttpUtil.post(apiUrl.getDeleteXinghuoDatasetUrl(), params, headers, null);\n        return JSON.parseObject(response);\n    }\n","sourceCodeStart":876,"sourceCodeEnd":912,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/repo/RepoService.java#L876-L912","documentation":"enableRepo computes the requested status transition: CREATED/PUBLISHED -> enabled=0 means UNPUBLISHED, UNPUBLISHED -> enabled=1 means PUBLISHED. Any other (status, enabled) combination — e.g. enabling an already-published repo, disabling an already-unpublished repo, or transitioning from intermediate statuses like BUILDING/FAILED — throws REPO_STATUS_ILLEGAL. It is a state-machine guard before updateRepoStatus.","triggerScenarios":"enabled=1 on a repo already in PUBLISHED status; enabled=0 on a repo already UNPUBLISHED; enabling/disabling a repo in a transitional status (building, indexing, failed) not covered by the two allowed branches.","commonSituations":"Idempotent retry of an enable call that already succeeded; double-click on the publish button; scripts assuming toggle semantics while the API expects exact target-state semantics; repos stuck in a failed build status being force-enabled.","solutions":["Check repo.getStatus() first and only call enableRepo when the transition matches the allowed matrix (CREATED/PUBLISHED->0, UNPUBLISHED->1)","Make callers idempotent: skip the call if the repo is already in the target state","Wait for pending build/index processes to finish before publishing","Catch BusinessException(REPO_STATUS_ILLEGAL), re-fetch current status, and reconcile the UI"],"exampleFix":"// before\nrepoService.enableRepo(id, 1); // fails if already published\n// after\nRepo repo = repoService.getById(id);\nif (!Objects.equals(repo.getStatus(), ProjectContent.REPO_STATUS_PUBLISHED)) {\n    repoService.enableRepo(id, 1);\n}","handlingStrategy":"validation","validationCode":"Repo repo = repoService.getById(id);\nboolean valid =\n    (Objects.equals(repo.getStatus(), ProjectContent.REPO_STATUS_CREATED)\n  || Objects.equals(repo.getStatus(), ProjectContent.REPO_STATUS_PUBLISHED)) && enabled == 0\n  || (Objects.equals(repo.getStatus(), ProjectContent.REPO_STATUS_UNPUBLISHED) && enabled == 1);\nif (!valid) throw new IllegalStateException(\"Illegal repo status transition\");","typeGuard":null,"tryCatchPattern":"try {\n    repoService.enableRepo(id, enabled);\n} catch (BusinessException e) {\n    if (\"REPO_STATUS_ILLEGAL\".equals(e.getCode())) {\n        Repo cur = repoService.getById(id); // re-sync state\n    }\n}","preventionTips":["Make enable calls idempotent: check current status first","Debounce publish/unpublish buttons in the UI","Wait for build/index completion before status changes","Map the full status transition matrix in client code and validate against it"],"tags":["knowledge-base","state-machine","invalid-transition"],"backgroundTag":"invalid-state-transition","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}