{"record":{"id":"2d47f9933b0796ce","repo":"apolloconfig/apollo","slug":"read-config-file-errors","errorCode":null,"errorMessage":"Read config file errors:{}","messagePattern":"Read config file errors:(.+?)","errorType":"exception","errorClass":"ServiceException","httpStatus":500,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java","lineNumber":96,"sourceCode":"    this.itemService = itemService;\n    this.appService = appService;\n    this.clusterService = clusterService;\n    this.namespaceService = namespaceService;\n    this.appNamespaceService = appNamespaceService;\n    this.publisher = publisher;\n    this.roleInitializationService = roleInitializationService;\n  }\n\n  /**\n   * force import, new items will overwrite existed items.\n   */\n  public void forceImportNamespaceFromFile(final Env env, final String standardFilename,\n      final InputStream zipInputStream, String operator) {\n    String configText;\n    try (InputStream in = zipInputStream) {\n      configText = ConfigToFileUtils.fileToString(in);\n    } catch (IOException e) {\n      throw new ServiceException(\"Read config file errors:{}\", e);\n    }\n\n    this.importNamespaceFromText(env, standardFilename, configText, false, operator);\n  }\n\n  /**\n   * import all data include app、appnamespace、cluster、namespace、item\n   */\n  public void importDataFromZipFile(List<Env> importEnvs, ZipInputStream dataZip,\n      boolean ignoreConflictNamespace, String operator) throws IOException {\n    List<String> toImportApps = Lists.newArrayList();\n    List<String> toImportAppNSs = Lists.newArrayList();\n    List<ImportClusterData> toImportClusters = Lists.newArrayList();\n    List<ImportNamespaceData> toImportNSs = Lists.newArrayList();\n\n    ZipEntry entry;\n    while ((entry = dataZip.getNextEntry()) != null) {\n      if (entry.isDirectory()) {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsImportService.java#L78-L114","documentation":"Thrown by ConfigsImportService.forceImportNamespaceFromFile() when reading the provided InputStream into a String via ConfigToFileUtils.fileToString() fails with an IOException. This is the first step of a forced namespace import — the uploaded file content cannot be read, so the import aborts before any parsing or application.","triggerScenarios":"Calling forceImportNamespaceFromFile with a corrupted, empty, or prematurely-closed InputStream. The try-with-resources closes the stream, and any read failure (malformed bytes, broken upload, stream already consumed) surfaces as ServiceException.","commonSituations":"Upload of a malformed or truncated config file; multipart upload where the InputStream was already consumed by another reader; character encoding mismatch causing read failure; network interruption during file upload.","solutions":["Verify the uploaded file is valid and non-empty before calling the import API.","Ensure the InputStream is not consumed or closed before being passed to forceImportNamespaceFromFile.","Check the file encoding matches what ConfigToFileUtils.fileToString() expects.","Inspect portal logs for the underlying IOException cause to distinguish corruption from encoding issues."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate the input stream before import\nif (zipInputStream == null || zipInputStream.available() == 0) {\n  throw new IllegalArgumentException(\"Input stream is null or empty\");\n}\nbyte[] bytes = zipInputStream.readAllBytes();\nif (bytes.length == 0) {\n  throw new IllegalArgumentException(\"Config file content is empty\");\n}\nString configText = new String(bytes, StandardCharsets.UTF_8);","typeGuard":null,"tryCatchPattern":"try {\n  configsImportService.forceImportNamespaceFromFile(env, filename, inputStream, operator);\n} catch (ServiceException e) {\n  if (e.getMessage().contains(\"Read config file errors\")) {\n    log.error(\"Failed to read uploaded config file\", e);\n    // prompt user to re-upload a valid file\n  }\n  throw e;\n}","preventionTips":["Validate the uploaded file is non-empty and well-formed before passing to the import service.","Ensure the InputStream is not consumed by multipart parsing or other readers before import.","Use UTF-8 encoding consistently for config file content."],"tags":["apollo-portal","config-import","io","input-stream","service-exception"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}