{"record":{"id":"46581fade5f75f20","repo":"jdx/mise","slug":"file-cannot-be-present-while-managed-parent","errorCode":null,"errorMessage":"file '{}' cannot be present while managed parent '{}' is absent","messagePattern":"file '(.+?)' cannot be present while managed parent '(.+?)' is absent","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/resources.rs","lineNumber":512,"sourceCode":"            let parent_id = ResourceId::new(\"directory\", parent.to_string_lossy());\n            match (file.state, parent_state) {\n                (\n                    super::managed_files::ManagedState::Present,\n                    super::managed_files::ManagedState::Present,\n                ) => {\n                    plan.add_dependency(&id, parent_id)?;\n                }\n                (\n                    super::managed_files::ManagedState::Absent,\n                    super::managed_files::ManagedState::Absent,\n                ) => {\n                    plan.add_dependency(&parent_id, id)?;\n                }\n                (\n                    super::managed_files::ManagedState::Present,\n                    super::managed_files::ManagedState::Absent,\n                ) => {\n                    bail!(\n                        \"file '{}' cannot be present while managed parent '{}' is absent\",\n                        file.path.display(),\n                        parent.display()\n                    );\n                }\n                (\n                    super::managed_files::ManagedState::Absent,\n                    super::managed_files::ManagedState::Present,\n                ) => {}\n            }\n        }\n    }\n    for resource in unavailable_files {\n        plan.insert(resource)?;\n    }\n    let service_dependencies = plan\n        .resources\n        .keys()","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/resources.rs#L494-L530","documentation":"This error is thrown when the declarative file-resource planner detects a state contradiction: a managed file is requested to be Present while the managed parent directory it lives under is requested to be Absent. The planner refuses to build such a plan because it cannot both create and delete the containing directory chain in a consistent order. It is a plan-time (pre-apply) guard, so nothing is modified when it fires.","triggerScenarios":"Calling the planning phase (plan) where one resource declares a parent directory with managed state Absent and another resource declares a file inside that directory with managed state Present; plan.add_dependency for the parent has already succeeded, so the contradiction is in requested states, not ordering.","commonSituations":"Splitting desired-state config across files where one module removes a directory (state = absent) while another module still manages config files inside it; leftover file entries after a refactor that deleted the parent directory resource; typos in the parent path so two resources disagree about which path is the parent.","solutions":["Set the parent directory resource to state Present (or stop managing it as Absent) so the child file can exist.","Remove or set to Absent the child file resources that live under the directory being removed.","Reconcile the two declarations so both agree: if the tree is going away, mark children absent too; if children stay, the parent must stay.","Fix path mismatches (trailing slashes, symlinks, relative vs absolute paths) if the parent/child relationship is accidental."],"exampleFix":"// before\nmanaged_dir(\"/opt/app\", ManagedState::Absent);\nmanaged_file(\"/opt/app/config.toml\", ManagedState::Present);\n// after\nmanaged_dir(\"/opt/app\", ManagedState::Present);\nmanaged_file(\"/opt/app/config.toml\", ManagedState::Present);","handlingStrategy":"validation","validationCode":"fn validate_parent_child(dir: (&str, bool), file: (&str, bool)) -> Result<(), String> {\n    let (dir_path, dir_present) = dir;\n    let (file_path, file_present) = file;\n    if file_present && !dir_present && file_path.starts_with(dir_path) {\n        return Err(format!(\"{file_path} is present but parent {dir_path} is absent\"));\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep desired-state for a directory tree in one place so parent/child states cannot diverge","When removing a directory, audit all resources under that path and mark them absent too","Lint config for files whose path is a prefix-child of a directory declared absent","Use consistent path normalization (absolute, no trailing slash) so parent relationships are detected"],"tags":["state-management","filesystem","planning"],"backgroundTag":"invalid-state-transition","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}