apolloconfig/apollo · error · BadRequestException
import namespace items failed: %s
Error message
import namespace items failed: %s
What it means
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.
Source
Thrown at apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/PortalManagementController.java:700
}
@Override
@PreAuthorize(
value = "@unifiedPermissionValidator.hasModifyNamespacePermission(#appId, #env, #clusterName, #namespaceName)")
public ResponseEntity<Void> importNamespaceItems(String appId, String env, String clusterName,
String namespaceName, MultipartFile file) {
requirePortalUserRequest();
Env targetEnv = parseEnv(env);
try {
ConfigFileUtils.check(file);
String format = ConfigFileUtils.getFormat(file.getOriginalFilename());
String standardFilename = ConfigFileUtils.toFilename(appId, clusterName, namespaceName,
ConfigFileFormat.fromString(format));
configsImportService.forceImportNamespaceFromFile(targetEnv, standardFilename,
file.getInputStream(), currentUserId());
return ResponseEntity.ok().build();
} catch (IOException e) {
throw new BadRequestException("import namespace items failed: %s", e.getMessage());
}
}
private Consumer convertToConsumer(ConsumerCreateRequestVO request) {
Consumer consumer = new Consumer();
consumer.setAppId(request.getAppId());
consumer.setName(request.getName());
consumer.setOwnerName(request.getOwnerName());
consumer.setOrgId(request.getOrgId());
consumer.setOrgName(request.getOrgName());
return consumer;
}
private void validateConsumerCreateRequest(ConsumerCreateRequestVO request) {
if (StringUtils.isBlank(request.getAppId())) {
throw BadRequestException.appIdIsBlank();
}
if (StringUtils.isBlank(request.getName())) {View on GitHub (pinned to d95fc18d11)
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.
Example fix
// before: file has no extension or is empty curl -F 'file=@/dev/null' // after: valid config file with extension curl -F 'file=@application.properties'
Defensive patterns
Strategy: validation
Validate before calling
// Validate file is non-empty and has a valid extension before import
String name = file.getOriginalFilename();
if (file.isEmpty() || name == null || !name.contains(".")) {
throw new IllegalArgumentException("File must be non-empty with a valid extension");
} Type guard
function isValidConfigFile(file: File): boolean {
return file.size > 0 && /\.(properties|yml|yaml|json|xml|txt)$/i.test(file.name);
} Try / catch
try {
importNamespaceItems(appId, env, cluster, namespace, file);
} catch (BadRequestException e) {
if (e.getMessage().contains("import namespace items failed")) {
// validate file format and content, then retry
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- import configs failed: %s
- import app configs failed: %s
- create namespace failed for: %s
- Namespace's role does not exist. Please check whether namesp
- Current user not found
AI-assisted analysis of apolloconfig/apollo@d95fc18d11 (2026-08-14).
Data as JSON: /api/errors/74a70b2d450ad19e.
Report an issue: GitHub.