{"record":{"id":"62abb861a65c17cb","repo":"iflytek/astron-agent","slug":"repo-create-ragflow-failed","errorCode":"REPO_CREATE_RAGFLOW_FAILED","errorMessage":"RAGFlow returned blank datasetId","messagePattern":"RAGFlow returned blank datasetId","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/handler/KnowledgeV2ServiceCallHandler.java","lineNumber":63,"sourceCode":"        Map<String, String> headers = buildKnowledgeHeaders(ProjectContent.FILE_SOURCE_RAG_FLOW_RAG_STR);\n        DatasetCreateRequest req = new DatasetCreateRequest(name, description);\n        String reqBody = JSON.toJSONString(req);\n        log.info(\"createRagflowDataset url = {}, name = {}\", url, name);\n        String resp = postJson(url, headers, reqBody);\n        log.info(\"createRagflowDataset response = {}\", resp);\n        KnowledgeResponse parsed = JSON.parseObject(resp, KnowledgeResponse.class);\n        if (parsed == null || parsed.getCode() == null || parsed.getCode() != 0) {\n            String msg = (parsed == null) ? \"blank response\" : parsed.getMessage();\n            throw new BusinessException(ResponseEnum.REPO_CREATE_RAGFLOW_FAILED, msg);\n        }\n        return extractDatasetId(parsed.getData());\n    }\n\n    private String extractDatasetId(Object data) {\n        JSONObject dataObj = toJsonObject(data);\n        String datasetId = dataObj == null ? null : dataObj.getString(DATASET_ID_FIELD);\n        if (StringUtils.isBlank(datasetId)) {\n            throw new BusinessException(ResponseEnum.REPO_CREATE_RAGFLOW_FAILED,\n                    \"RAGFlow returned blank datasetId\");\n        }\n        return datasetId;\n    }\n\n    private JSONObject toJsonObject(Object data) {\n        if (data instanceof JSONObject) {\n            return (JSONObject) data;\n        }\n        if (data instanceof String) {\n            return JSON.parseObject((String) data);\n        }\n        throw new BusinessException(ResponseEnum.REPO_CREATE_RAGFLOW_FAILED,\n                \"RAGFlow returned non-object data\");\n    }\n\n    /**\n     * Document parsing and chunking","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/handler/KnowledgeV2ServiceCallHandler.java#L45-L81","documentation":"extractDatasetId() parses the response body of a RAGFlow dataset-creation API call and reads the datasetId field. If the parsed JSON object lacks the field or it is blank, it throws BusinessException(ResponseEnum.REPO_CREATE_RAGFLOW_FAILED, \"RAGFlow returned blank datasetId\"). It indicates the knowledge-base creation request reached RAGFlow but the response did not contain the expected identifier.","triggerScenarios":"Creating a RAGFlow-backed knowledge repository where the create-dataset HTTP call returns 200 but data.datasetId is missing, null, or an empty string in the JSON payload.","commonSituations":"RAGFlow returns an error payload wrapped in a 200 response (its error inside data/message instead of HTTP status); RAGFlow version changed the response field name; wrong RAGFlow API key/tenant causing a success-shaped but empty body; network proxy mangling the response.","solutions":["Log the full RAGFlow response body before extraction and inspect whether it actually contains a datasetId or an embedded error message.","Verify the RAGFlow API key and tenant configuration; auth failures can surface as success-shaped empty payloads.","Check the RAGFlow version's API docs for the dataset-creation response schema and update DATASET_ID_FIELD if the field was renamed.","If RAGFlow returned an embedded error, surface that message to the caller instead of the generic blank-datasetId error."],"exampleFix":"// before\nString datasetId = dataObj == null ? null : dataObj.getString(DATASET_ID_FIELD);\n\n// after\nString datasetId = dataObj == null ? null : dataObj.getString(DATASET_ID_FIELD);\nif (StringUtils.isBlank(datasetId) && dataObj != null && dataObj.containsKey(\"code\") && dataObj.getIntValue(\"code\") != 0) {\n    log.error(\"RAGFlow create dataset failed: {}\", dataObj.toJSONString());\n}","handlingStrategy":"try-catch","validationCode":"JSONObject resp = toJsonObject(ragflowCreateResponse);\nif (resp == null || StringUtils.isBlank(resp.getString(\"datasetId\"))) {\n  throw new Error('RAGFlow response has no datasetId: ' + JSON.toJSONString(resp));\n}","typeGuard":"boolean hasDatasetId(Object data) {\n    JSONObject o = (data instanceof JSONObject) ? (JSONObject) data : null;\n    return o != null && StringUtils.isNotBlank(o.getString(\"datasetId\"));\n}","tryCatchPattern":"try {\n    String id = createRagflowDataset(req);\n} catch (BusinessException e) {\n    log.error('RAGFlow create dataset failed: {}', e.getMessage());\n    // inspect full RAGFlow body for embedded error before retrying\n}","preventionTips":["Log the complete RAGFlow response body on every create call so blank-datasetId cases are diagnosable.","Verify RAGFlow API key/tenant configuration in the deployment environment.","Pin the RAGFlow version and re-check the create-dataset response schema on upgrades."],"tags":["ragflow","api-response","knowledge-base","integration","java"],"backgroundTag":"unexpected-api-response-shape","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"}