{"record":{"id":"74a70b2d450ad19e","repo":"apolloconfig/apollo","slug":"import-namespace-items-failed-s","errorCode":null,"errorMessage":"import namespace items failed: %s","messagePattern":"import namespace items failed: (.+?)","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/PortalManagementController.java","lineNumber":700,"sourceCode":"  }\n\n  @Override\n  @PreAuthorize(\n      value = \"@unifiedPermissionValidator.hasModifyNamespacePermission(#appId, #env, #clusterName, #namespaceName)\")\n  public ResponseEntity<Void> importNamespaceItems(String appId, String env, String clusterName,\n      String namespaceName, MultipartFile file) {\n    requirePortalUserRequest();\n    Env targetEnv = parseEnv(env);\n    try {\n      ConfigFileUtils.check(file);\n      String format = ConfigFileUtils.getFormat(file.getOriginalFilename());\n      String standardFilename = ConfigFileUtils.toFilename(appId, clusterName, namespaceName,\n          ConfigFileFormat.fromString(format));\n      configsImportService.forceImportNamespaceFromFile(targetEnv, standardFilename,\n          file.getInputStream(), currentUserId());\n      return ResponseEntity.ok().build();\n    } catch (IOException e) {\n      throw new BadRequestException(\"import namespace items failed: %s\", e.getMessage());\n    }\n  }\n\n  private Consumer convertToConsumer(ConsumerCreateRequestVO request) {\n    Consumer consumer = new Consumer();\n    consumer.setAppId(request.getAppId());\n    consumer.setName(request.getName());\n    consumer.setOwnerName(request.getOwnerName());\n    consumer.setOrgId(request.getOrgId());\n    consumer.setOrgName(request.getOrgName());\n    return consumer;\n  }\n\n  private void validateConsumerCreateRequest(ConsumerCreateRequestVO request) {\n    if (StringUtils.isBlank(request.getAppId())) {\n      throw BadRequestException.appIdIsBlank();\n    }\n    if (StringUtils.isBlank(request.getName())) {","sourceCodeStart":682,"sourceCodeEnd":718,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/PortalManagementController.java#L682-L718","documentation":"Thrown in importNamespaceItems when an IOException occurs while reading or validating the uploaded config file for a single-namespace import. Before import, ConfigFileUtils.check validates the file and getFormat determines the config format from the filename. The error message includes the underlying IOException detail.","triggerScenarios":"A user uploads a single config file (properties, yaml, json, etc.) to import into a namespace, but the file read or format-check step throws an IOException.","commonSituations":"The uploaded file is empty (0 bytes); the original filename has no extension so format detection fails; the file content does not match the expected format; or the multipart stream was already consumed/corrupted.","solutions":["Ensure the uploaded file is non-empty and has a recognizable extension (.properties, .yml, .yaml, .json, .xml, .txt).","Verify the file content is valid for its claimed format before uploading.","Check the IOException detail appended to the message for the precise failure.","If using a client library, ensure it sends the file with the correct original filename and content."],"exampleFix":"// before: file has no extension or is empty\ncurl -F 'file=@/dev/null'\n\n// after: valid config file with extension\ncurl -F 'file=@application.properties'","handlingStrategy":"validation","validationCode":"// Validate file is non-empty and has a valid extension before import\nString name = file.getOriginalFilename();\nif (file.isEmpty() || name == null || !name.contains(\".\")) {\n  throw new IllegalArgumentException(\"File must be non-empty with a valid extension\");\n}","typeGuard":"function isValidConfigFile(file: File): boolean {\n  return file.size > 0 && /\\.(properties|yml|yaml|json|xml|txt)$/i.test(file.name);\n}","tryCatchPattern":"try {\n  importNamespaceItems(appId, env, cluster, namespace, file);\n} catch (BadRequestException e) {\n  if (e.getMessage().contains(\"import namespace items failed\")) {\n    // validate file format and content, then retry\n  }\n}","preventionTips":["Check file size > 0 and filename has a known extension before upload.","Validate file content matches the format implied by the extension.","Test imports in a dev environment before production."],"tags":["io","openapi","bad-request","import","namespace","config-file","apollo-portal"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}