openai/codex · error · std::io::Error

failed to canonicalize CODEX_HOME

Error message

failed to canonicalize CODEX_HOME {val:?}: {err}

What it means

find_codex_home_from_env successfully stat'ed the CODEX_HOME directory but path.canonicalize() failed (e.g. broken symlink, permission issue on traversal, or race during resolution); the original error kind is preserved with added context.

Solutions

  1. Fix the broken symlink or traversal permissions on the CODEX_HOME path
  2. Use a real directory path instead of a symlink chain
  3. Retry if a concurrent modification raced the canonicalization
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at codex-rs/utils/home-dir/src/lib.rs:44 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/f25387310d9a0ea2. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/utils/home-dir/src/lib.rs:44

            let metadata = std::fs::metadata(&path).map_err(|err| match err.kind() {
                std::io::ErrorKind::NotFound => std::io::Error::new(
                    std::io::ErrorKind::NotFound,
                    format!("CODEX_HOME points to {val:?}, but that path does not exist"),
                ),
                _ => std::io::Error::new(
                    err.kind(),
                    format!("failed to read CODEX_HOME {val:?}: {err}"),
                ),
            })?;

            if !metadata.is_dir() {
                Err(std::io::Error::new(
                    std::io::ErrorKind::InvalidInput,
                    format!("CODEX_HOME points to {val:?}, but that path is not a directory"),
                ))
            } else {
                let canonical = path.canonicalize().map_err(|err| {
                    std::io::Error::new(
                        err.kind(),
                        format!("failed to canonicalize CODEX_HOME {val:?}: {err}"),
                    )
                })?;
                AbsolutePathBuf::from_absolute_path(canonical)
            }
        }
        None => {
            let mut p = home_dir().ok_or_else(|| {
                std::io::Error::new(
                    std::io::ErrorKind::NotFound,
                    "Could not find home directory",
                )
            })?;
            p.push(".codex");
            AbsolutePathBuf::from_absolute_path(p)
        }
    }

View on GitHub (pinned to 339751715c)