nikivdev/code · warning
invalid policy path {}
Error message
invalid policy path {} What it means
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.
Source
Thrown at src/gitignore_policy.rs:267
v.line,
v.entry,
v.blocked_pattern
);
}
}
if apply_fix {
bail!("Some blocked entries remain; review output above")
} else {
bail!("Found blocked personal-tooling entries")
}
}
fn init_policy_file(opts: GitignorePolicyInitOpts) -> Result<()> {
let path = policy_path();
let parent = path
.parent()
.ok_or_else(|| anyhow::anyhow!("invalid policy path {}", path.display()))?;
fs::create_dir_all(parent).with_context(|| format!("failed to create {}", parent.display()))?;
if path.exists() && !opts.force {
bail!(
"{} already exists (use --force to overwrite)",
path.display()
);
}
fs::write(&path, default_policy_template())
.with_context(|| format!("failed to write {}", path.display()))?;
println!("Wrote {}", path.display());
Ok(())
}
fn setup_global_gitignore(print_only: bool) -> Result<()> {
let policy = load_policy();
let target = resolve_global_excludes_path()?;View on GitHub (pinned to a747e741ae)
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
Example fix
// before
let path = policy_path(); // resolved to "/"
// after
let path = policy_path();
assert!(path.parent().is_some(), "policy path needs a parent dir: {}", path.display()); Defensive patterns
Strategy: validation
Validate before calling
let path = policy_path();
if path.parent().is_none() {
anyhow::bail!("policy path must include a parent dir, got {}", path.display());
} Type guard
fn has_parent(p: &std::path::Path) -> bool { p.parent().is_some() } Try / catch
if let Err(e) = init_policy_file(opts) {
if e.to_string().starts_with("invalid policy path") {
eprintln!("fix policy path config / HOME env");
} else { return Err(e); }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Misconfigured HOME/env so the policy path collapses to a root-only path; overriding the policy path to "/" or empty in config or environment.
Related errors
- Postgres project path not found: {} (override with --project
- Path not found: {}
- config path not found: {}
- target path exists but is not a git checkout: {}
- No flow.toml found in current directory
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/5366b7cb68a6ceec.
Report an issue: GitHub.