{"record":{"id":"feb5b6554b47adf3","repo":"floci-io/floci","slug":"resourcenotfoundexception","errorCode":"ResourceNotFoundException","errorMessage":"Environment not found in this application","messagePattern":"Environment not found in this application","errorType":"error_code","errorClass":"AwsException","httpStatus":404,"severity":"error","filePath":"src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigService.java","lineNumber":77,"sourceCode":"    }\n\n    // ──────────────────────────── Environment ────────────────────────────\n\n    public Environment createEnvironment(String appId, Map<String, Object> request) {\n        getApplication(appId);\n        Environment env = new Environment();\n        env.setId(shortId(7));\n        env.setApplicationId(appId);\n        env.setName((String) request.get(\"Name\"));\n        env.setDescription((String) request.get(\"Description\"));\n        env.setState(\"READY\");\n        environmentStore.put(env.getId(), env);\n        return env;\n    }\n\n    public Environment getEnvironment(String appId, String envId) {\n        Environment env = environmentStore.get(envId).orElseThrow(() -> new AwsException(\"ResourceNotFoundException\", \"Environment not found\", 404));\n        if (!env.getApplicationId().equals(appId)) throw new AwsException(\"ResourceNotFoundException\", \"Environment not found in this application\", 404);\n        return env;\n    }\n\n    public List<Environment> listEnvironments(String appId) {\n        return environmentStore.scan(k -> true).stream()\n                .filter(e -> e.getApplicationId().equals(appId))\n                .toList();\n    }\n\n    // ──────────────────────────── Configuration Profile ────────────────────────────\n\n    public ConfigurationProfile createConfigurationProfile(String appId, Map<String, Object> request) {\n        getApplication(appId);\n        ConfigurationProfile profile = new ConfigurationProfile();\n        profile.setId(shortId(7));\n        profile.setApplicationId(appId);\n        profile.setName((String) request.get(\"Name\"));\n        profile.setDescription((String) request.get(\"Description\"));","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/floci-io/floci/blob/62ff490619e7bd3554597c28c704081b4c15add5/src/main/java/io/github/hectorvent/floci/services/appconfig/AppConfigService.java#L59-L95","documentation":"Thrown by AppConfigService.getEnvironment() when an environment with the given envId exists in the store but belongs to a different application than the appId supplied. The first lookup ('Environment not found') covers a nonexistent envId; this second check covers an ID/ownership mismatch and deliberately returns the same ResourceNotFoundException (404) with a distinguishing message, mirroring AWS's behavior of not leaking cross-application resource existence.","triggerScenarios":"Calling GetEnvironmentConfiguration / GetEnvironment with the right envId but the wrong ApplicationId — e.g. copy-pasting an app id from another profile, or a test fixture that created the environment under app A and queries it under app B. Environment ids are shortId(7) values unique across the store, so a hit with a different owner is always an ownership mismatch, not an id collision.","commonSituations":"Scripts that hardcode application ids and drift after recreating the application. Configuration files where the app identifier was refreshed but the environment references were not. Multi-application tenants where the same logical env name exists under two apps and the wrong app's id is used.","solutions":["List environments under the application you think owns it (ListEnvironments with that appId) and use the envId it returns.","Cross-check the appId: ListApplications and confirm the id in your command matches the application that created the environment.","If the application was recreated, re-create the environment under the new app id and update references.","Keep app/env id pairs together in one config block instead of assembling them from independent variables."],"exampleFix":"# before\naws appconfig get-environment \\\n  --application-id wrongapp1 --environment-id e123abc\n\n# after (find the true owner first)\naws appconfig list-environments --application-id realapp2\naws appconfig get-environment \\\n  --application-id realapp2 --environment-id e123abc","handlingStrategy":"try-catch","validationCode":"// Confirm ownership before fetching\nboolean owned = appConfig.listEnvironments(appId).stream()\n    .anyMatch(e -> e.getId().equals(envId));\nif (!owned) {\n    throw new IllegalArgumentException(\"env \" + envId + \" not under application \" + appId);\n}\nEnvironment env = appConfig.getEnvironment(appId, envId);","typeGuard":null,"tryCatchPattern":"catch (AwsException e) {\n    if (\"ResourceNotFoundException\".equals(e.getCode())) {\n        if (e.getMessage().contains(\"in this application\")) {\n            // ownership mismatch: resolve the true owner via listEnvironments on other apps\n            log.warn(\"{} belongs to another application; listing apps to relocate\", envId);\n        }\n        // both variants are terminal 404s — never retry\n        return Optional.empty();\n    }\n    throw e;\n}","preventionTips":["Treat (appId, envId) as an atomic pair everywhere in configuration.","After recreating an application, re-create or re-link its environments and update references.","Use ListEnvironments to discover ids instead of hardcoding them."],"tags":["appconfig","environment","not-found","ownership"],"backgroundTag":null,"analyzedSha":"62ff490619e7bd3554597c28c704081b4c15add5","analyzedAt":"2026-08-14T14:25:23.764Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}