{"record":{"id":"37af1c6fdefca790","repo":"iflytek/astron-agent","slug":"workflow-import-failed","errorCode":"WORKFLOW_IMPORT_FAILED","errorMessage":"WORKFLOW_IMPORT_FAILED","messagePattern":"WORKFLOW_IMPORT_FAILED","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/workflow/impl/BotMaasServiceImpl.java","lineNumber":148,"sourceCode":"            throw new BusinessException(ResponseEnum.PARAMETER_ERROR);\n        }\n\n        ExportedWorkflowTemplate template = loadAvailableTemplate(uid, templateId);\n        if (template == null || StringUtils.isBlank(template.getSnapshotYaml())) {\n            log.warn(\"Create workflow from exported template failed, templateId={}, uid={}, spaceId={}, templateFound={}, snapshotBlank={}\",\n                    templateId,\n                    uid,\n                    SpaceInfoUtil.getSpaceId(),\n                    template != null,\n                    template == null || StringUtils.isBlank(template.getSnapshotYaml()));\n            throw new BusinessException(ResponseEnum.BOT_NOT_EXIST);\n        }\n\n        ApiResult<?> importResult = workflowExportService.importWorkflowFromYaml(\n                new ByteArrayInputStream(template.getSnapshotYaml().getBytes(StandardCharsets.UTF_8)),\n                request);\n        if (importResult.code() != 0 || !(importResult.data() instanceof Workflow importedWorkflow)) {\n            throw new BusinessException(ResponseEnum.WORKFLOW_IMPORT_FAILED);\n        }\n\n        JSONObject ext = JSONObject.parseObject(importedWorkflow.getExt());\n        BotInfoDto botInfoDto = new BotInfoDto();\n        botInfoDto.setBotId(ext == null ? null : ext.getInteger(\"botId\"));\n        botInfoDto.setBotName(importedWorkflow.getName());\n        botInfoDto.setBotDesc(importedWorkflow.getDescription());\n        botInfoDto.setAvatar(importedWorkflow.getAvatarIcon());\n        botInfoDto.setVersion(BotVersionEnum.WORKFLOW.getVersion());\n        botInfoDto.setFlowId(importedWorkflow.getId());\n        botInfoDto.setMaasId(importedWorkflow.getId());\n        return botInfoDto;\n    }\n\n    private ExportedWorkflowTemplate loadAvailableTemplate(String uid, Long templateId) {\n        ExportedWorkflowTemplate template = exportedWorkflowTemplateMapper.selectById(templateId);\n        if (template == null || !Objects.equals(template.getIsDelete(), (byte) 0)) {\n            log.warn(\"Exported workflow template unavailable, templateId={}, uid={}, templateFound={}, isDelete={}\",","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/workflow/impl/BotMaasServiceImpl.java#L130-L166","documentation":"Thrown when workflowExportService.importWorkflowFromYaml returns a non-zero code or its data is not a Workflow instance. The template snapshot YAML failed to import into the workflow engine, so creation from the exported template aborts.","triggerScenarios":"createFromExportedTemplate invoking importWorkflowFromYaml(new ByteArrayInputStream(snapshotYaml bytes), request) where the import service returns code != 0 or an unexpected data payload (not Workflow).","commonSituations":"Snapshot YAML produced by an older exporter version that current import logic rejects, YAML corrupted by charset/encoding issues, referenced nodes/plugins missing in the target environment, or import API contract change (data wrapped differently so the instanceof check fails).","solutions":["Log importResult.code() and message to get the importer's concrete failure reason","Validate the snapshot YAML against the current workflow schema; re-export the template if it is from an old version","Ensure UTF-8 is used consistently when the YAML was stored/retrieved (getBytes(StandardCharsets.UTF_8))","Confirm importWorkflowFromYaml still returns ApiResult<Workflow>; adjust the unwrapping if the response shape changed"],"exampleFix":"// before\nif (importResult.code() != 0 || !(importResult.data() instanceof Workflow importedWorkflow)) {\n    throw new BusinessException(ResponseEnum.WORKFLOW_IMPORT_FAILED);\n}\n// after\nif (importResult.code() != 0 || !(importResult.data() instanceof Workflow importedWorkflow)) {\n    log.error(\"YAML import failed, templateId={}, code={}, msg={}\", templateId, importResult.code(), importResult.message());\n    throw new BusinessException(ResponseEnum.WORKFLOW_IMPORT_FAILED);\n}","handlingStrategy":"try-catch","validationCode":"// pre-validate snapshot shape before import\nif (template.getSnapshotYaml() == null || !template.getSnapshotYaml().contains(\"nodes\")) {\n    return ApiResult.fail(\"snapshot YAML malformed\");\n}","typeGuard":"Object data = importResult.data();\nif (importResult.code() == 0 && data instanceof Workflow wf) { /* proceed with wf */ }","tryCatchPattern":"try {\n    botMaasService.createFromTemplate(uid, req, httpRequest);\n} catch (BusinessException e) {\n    if (ResponseEnum.WORKFLOW_IMPORT_FAILED.getCode().equals(e.getCode())) {\n        // ask user to re-export the template; log importResult.code()/message server-side\n    }\n    throw e;\n}","preventionTips":["Keep exporter and importer schema versions in sync","Always serialize snapshotYaml as UTF-8","Validate YAML on export, not only on import","Log the importer's code/message before throwing"],"tags":["yaml","import","workflow"],"backgroundTag":"yaml-parse-error","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"}