{"record":{"id":"f62a90e6d0b1cf2d","repo":"iflytek/astron-agent","slug":"8332-toolbox-import-file-format-error","errorCode":"8332","errorMessage":"toolbox.import.file.format.error","messagePattern":"toolbox\\.import\\.file\\.format\\.error","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/tool/ToolBoxService.java","lineNumber":2287,"sourceCode":"            String fileName = file.getOriginalFilename();\n            ObjectMapper jsonMapper = new ObjectMapper();\n            ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());\n\n            if (fileName == null) {\n                throw new BusinessException(ResponseEnum.TOOLBOX_IMPORT_FILE_NAME_NULL);\n            }\n\n            String lowerName = fileName.toLowerCase();\n\n            ToolBoxExportVo vo;\n            if (lowerName.endsWith(\".yaml\") || lowerName.endsWith(\".yml\")) {\n                // YAML -> ToolBoxExportVo\n                vo = yamlMapper.readValue(file.getInputStream(), ToolBoxExportVo.class);\n            } else if (lowerName.endsWith(\".json\")) {\n                // JSON -> ToolBoxExportVo\n                vo = jsonMapper.readValue(file.getInputStream(), ToolBoxExportVo.class);\n            } else {\n                throw new BusinessException(ResponseEnum.TOOLBOX_IMPORT_FILE_FORMAT_ERROR);\n            }\n            return vo;\n        } catch (Exception ex) {\n            log.error(\"Import failed\", ex);\n            if (ex instanceof BusinessException) {\n                throw (BusinessException) ex;\n            }\n            throw new BusinessException(ResponseEnum.TOOLBOX_IMPORT_ERROR);\n        }\n    }\n}\n","sourceCodeStart":2269,"sourceCodeEnd":2299,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/tool/ToolBoxService.java#L2269-L2299","documentation":"TOOLBOX_IMPORT_FILE_FORMAT_ERROR (code 8332) is thrown when the uploaded import file's extension is neither .yaml/.yml nor .json. The service only supports those two formats and rejects everything else before attempting to parse.","triggerScenarios":"Importing a file with a different extension (e.g. .txt, .xml, no extension) or no recognizable suffix at all.","commonSituations":"Users renaming an export without keeping the extension; exporting from another tool in a different format and uploading it directly; OS hiding extensions leading to files like tool.json.txt.","solutions":["Upload a file whose name ends with .json, .yaml, or .yml","Re-export the tool from the platform to get a correctly formatted file","Rename the file to add the proper extension if the content is actually JSON/YAML"],"exampleFix":"// before\nPOST import with file named \"mytool.txt\"\n// after\nPOST import with file named \"mytool.json\"","handlingStrategy":"validation","validationCode":"String n = file.getOriginalFilename().toLowerCase(); if (!n.endsWith(\".json\") && !n.endsWith(\".yaml\") && !n.endsWith(\".yml\")) { throw new IllegalArgumentException(\"only .json/.yaml/.yml imports are supported\"); }","typeGuard":"boolean isSupportedImportFile(String name) { if (name == null) return false; String n = name.toLowerCase(); return n.endsWith(\".json\") || n.endsWith(\".yaml\") || n.endsWith(\".yml\"); }","tryCatchPattern":"try { toolBoxApi.importTool(file); } catch (BusinessException e) { if (e.getCode() == 8332) { /* tell user to use .json/.yaml/.yml */ } else throw e; }","preventionTips":["Restrict file-picker accept attribute to .json,.yaml,.yml","Keep real extensions on export downloads","Educate users about OS-hidden double extensions (file.json.txt)"],"tags":["java","spring-boot","upload","file-format","toolbox"],"backgroundTag":"unsupported-file-format","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"}