Hmbown/CodeWhale · error

managed directory path cannot be empty

Error message

managed directory path cannot be empty

What it means

normalize_managed_dir normalizes the directory where the session manager stores its data. An empty PathBuf (no OS string content) cannot name a managed directory, so it is rejected with InvalidInput at construction time. This is a fail-loud config guard: an empty path is always a configuration mistake.

Solutions

  1. Set a concrete directory path in the config (e.g. ~/.local/share/codewhale/sessions) instead of an empty value.
  2. If sourced from an env var, ensure the variable is set before launching.
  3. Check the config-loading layer so an omitted key falls back to the documented default rather than an empty path.
  4. In programmatic use, supply PathBuf::from("/valid/dir") rather than PathBuf::new().

Example fix

// before
// config.toml
sessions_dir = ""
// after
// config.toml
sessions_dir = "/home/user/.local/share/codewhale/sessions"
Defensive patterns

Strategy: validation

Validate before calling

let dir = config.sessions_dir.as_deref().filter(|s| !s.is_empty())
    .ok_or_else(|| anyhow!("sessions_dir is required and cannot be empty"))?;

Prevention

When it happens

Trigger: Constructing the session manager via new() (or SessionManager::new-style construction) with a configured directory that resolves to an empty PathBuf — e.g. an unset/empty config field assigned to the managed dir.

Common situations: Config file has `sessions_dir = ""` or the key omitted and the loader left the raw empty default; an environment variable used for the dir was unset; programmatic construction passed PathBuf::new().

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/1522ca75ddceff1c. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/session_manager.rs:112

fn is_sha256_fingerprint(value: &str) -> bool {
    value.len() == 64
        && value
            .bytes()
            .all(|byte| byte.is_ascii_digit() || (b'a'..=b'f').contains(&byte))
}

const fn default_session_schema_version() -> u32 {
    CURRENT_SESSION_SCHEMA_VERSION
}

const fn default_queue_schema_version() -> u32 {
    CURRENT_QUEUE_SCHEMA_VERSION
}

fn normalize_managed_dir(path: PathBuf) -> std::io::Result<PathBuf> {
    if path.as_os_str().is_empty() {
        return Err(std::io::Error::new(
            std::io::ErrorKind::InvalidInput,
            "managed directory path cannot be empty",
        ));
    }
    if path.components().any(|component| {
        matches!(
            component,
            Component::ParentDir | Component::Prefix(_) | Component::RootDir
        )
    }) && path.is_relative()
    {
        return Err(std::io::Error::new(
            std::io::ErrorKind::InvalidInput,
            "managed directory path cannot contain traversal components",
        ));
    }
    if path.is_absolute() {
        return Ok(path);

View on GitHub (pinned to 73e0f67d83)