{"record":{"id":"60a5ae73ff19f73f","repo":"apolloconfig/apollo","slug":"server-config-not-found-for-key-s","errorCode":null,"errorMessage":"server config not found for key:%s","messagePattern":"server config not found for key:(.+?)","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"warning","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ServerConfigService.java","lineNumber":84,"sourceCode":"    BeanUtils.copyEntityProperties(serverConfig, storedConfig);\n    storedConfig.setDataChangeLastModifiedBy(modifiedBy);\n    return serverConfigRepository.save(storedConfig);\n  }\n\n  @Transactional\n  public ServerConfig createOrUpdateConfigDBConfig(Env env, ServerConfig serverConfig,\n      String modifiedBy) {\n    serverConfig.setDataChangeCreatedBy(modifiedBy);\n    serverConfig.setDataChangeLastModifiedBy(modifiedBy);\n    return serverConfigAPI.createOrUpdateConfigDBConfig(env, serverConfig);\n  }\n\n  @Transactional\n  public void deletePortalDBConfig(String key, String modifiedBy) {\n    ServerConfig storedConfig = serverConfigRepository.findByKey(key);\n\n    if (Objects.isNull(storedConfig)) {\n      throw new NotFoundException(\"server config not found for key:%s\", key);\n    }\n\n    storedConfig.setDeleted(true);\n    storedConfig.setDataChangeLastModifiedBy(modifiedBy);\n    serverConfigRepository.save(storedConfig);\n  }\n\n  public void deleteConfigDBConfig(Env env, String key, String cluster, String modifiedBy) {\n    serverConfigAPI.deleteConfigDBConfig(env, key, cluster, modifiedBy);\n  }\n}\n","sourceCodeStart":66,"sourceCodeEnd":96,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ServerConfigService.java#L66-L96","documentation":"Thrown as a NotFoundException by ServerConfigService.deletePortalDBConfig() when serverConfigRepository.findByKey(key) returns null for the given key. This means no server configuration entry exists in the portal database with that key, so there is nothing to soft-delete (set deleted=true). The check is a precondition guard before the delete operation.","triggerScenarios":"Calling deletePortalDBConfig with a key that does not exist in the portal's ServerConfig repository. The findByKey query returns null, and the NotFoundException is thrown before any modification.","commonSituations":"Typo in the config key; the config was already deleted (soft-deleted) in a previous operation; attempting to delete a config that only exists in a specific env's config DB (not the portal DB); key case sensitivity mismatch.","solutions":["Verify the config key exists in the portal server config table before calling delete.","Check if the config was already soft-deleted (deleted=true) in a previous operation.","If deleting a config-service-level config (not portal DB), use deleteConfigDBConfig(env, key, cluster, modifiedBy) instead.","List all server configs via the portal API/UI to confirm the exact key spelling."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify the server config key exists before deleting\nServerConfig config = serverConfigRepository.findByKey(key);\nif (config == null) {\n  // already deleted or never existed - treat as no-op or inform user\n  log.warn(\"Server config not found for key: {}, nothing to delete\", key);\n  return;\n}","typeGuard":null,"tryCatchPattern":"try {\n  serverConfigService.deletePortalDBConfig(key, modifiedBy);\n} catch (NotFoundException e) {\n  if (e.getMessage().contains(\"server config not found\")) {\n    log.warn(\"Config key '{}' not found, may have been already deleted\", key);\n    return; // treat as idempotent success\n  }\n  throw e;\n}","preventionTips":["List server configs before attempting delete to confirm the key exists.","Handle not-found gracefully — a missing config may already be deleted.","Distinguish portal DB configs from env-specific config DB configs."],"tags":["apollo-portal","server-config","not-found","delete","validation"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}