{"record":{"id":"5366b7cb68a6ceec","repo":"nikivdev/code","slug":"invalid-policy-path","errorCode":null,"errorMessage":"invalid policy path {}","messagePattern":"invalid policy path (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/gitignore_policy.rs","lineNumber":267,"sourceCode":"                v.line,\n                v.entry,\n                v.blocked_pattern\n            );\n        }\n    }\n\n    if apply_fix {\n        bail!(\"Some blocked entries remain; review output above\")\n    } else {\n        bail!(\"Found blocked personal-tooling entries\")\n    }\n}\n\nfn init_policy_file(opts: GitignorePolicyInitOpts) -> Result<()> {\n    let path = policy_path();\n    let parent = path\n        .parent()\n        .ok_or_else(|| anyhow::anyhow!(\"invalid policy path {}\", path.display()))?;\n    fs::create_dir_all(parent).with_context(|| format!(\"failed to create {}\", parent.display()))?;\n\n    if path.exists() && !opts.force {\n        bail!(\n            \"{} already exists (use --force to overwrite)\",\n            path.display()\n        );\n    }\n\n    fs::write(&path, default_policy_template())\n        .with_context(|| format!(\"failed to write {}\", path.display()))?;\n    println!(\"Wrote {}\", path.display());\n    Ok(())\n}\n\nfn setup_global_gitignore(print_only: bool) -> Result<()> {\n    let policy = load_policy();\n    let target = resolve_global_excludes_path()?;","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/gitignore_policy.rs#L249-L285","documentation":"init_policy_file resolves the gitignore policy file path and needs its parent directory to create it; if the path has no parent component (e.g. a bare relative path resolving to the root), it throws this error. It guards against calling fs::create_dir_all with an empty/invalid parent.","triggerScenarios":"Running the gitignore-policy init command when policy_path() returns a path whose .parent() is None — e.g. path configured as \"/\" or a degenerate relative path.","commonSituations":"Misconfigured HOME/env so the policy path collapses to a root-only path; overriding the policy path to \"/\" or empty in config or environment.","solutions":["Set a proper policy path like .gitignore-policy/config.toml with a parent directory","Fix HOME / relevant env var so policy_path() resolves under a real home dir","Pass a path with at least one directory component"],"exampleFix":"// before\nlet path = policy_path(); // resolved to \"/\"\n// after\nlet path = policy_path();\nassert!(path.parent().is_some(), \"policy path needs a parent dir: {}\", path.display());","handlingStrategy":"validation","validationCode":"let path = policy_path();\nif path.parent().is_none() {\n    anyhow::bail!(\"policy path must include a parent dir, got {}\", path.display());\n}","typeGuard":"fn has_parent(p: &std::path::Path) -> bool { p.parent().is_some() }","tryCatchPattern":"if let Err(e) = init_policy_file(opts) {\n    if e.to_string().starts_with(\"invalid policy path\") {\n        eprintln!(\"fix policy path config / HOME env\");\n    } else { return Err(e); }\n}","preventionTips":["Keep policy paths like ~/.config/f/gitignore-policy.toml","Don't override HOME to \"/\" in CI containers","Sanity-check derived paths in config at startup"],"tags":["filesystem","config","path"],"backgroundTag":"invalid-config-path","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}