sinelaw/fresh · critical · io::Error (NotFound)

Could not determine config directory

Error message

Could not determine config directory

What it means

DirectoryContext::from_system fails when it cannot determine the user config directory (dirs::config_dir() returns None, e.g. XDG_CONFIG_HOME unset and no home directory resolvable). It is thrown after the data-directory check, so the environment lacks both XDG style directories. Like the data-dir error, it is an environment problem.

Solutions

  1. Set XDG_CONFIG_HOME (or $HOME) in the environment before launch.
  2. For systemd services add Environment=HOME=/home/user or EnvFile=/etc/default/app.
  3. Verify the user's home directory exists and is resolvable.
Defensive patterns

Strategy: fallback

Validate before calling

if std::env::var("XDG_CONFIG_HOME").is_err() && std::env::var("HOME").is_err() {
    eprintln!("HOME/XDG_CONFIG_HOME unset; config directory cannot be resolved");
}

Try / catch

let ctx = DirectoryContext::from_system().or_else(|_| {
    std::env::set_var("XDG_CONFIG_HOME", "/tmp/fresh-config");
    DirectoryContext::from_system()
})?;

Prevention

When it happens

Trigger: Calling DirectoryContext::from_system() when DirectoryContext::default_config_dir() (backed by dirs::config_dir()) returns None — no XDG_CONFIG_HOME and no resolvable home.

Common situations: Headless services, containers, or cron jobs with an empty environment; broken user accounts without a home directory.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13). Data as JSON: /api/errors/6a057401d1b8187c. Report an issue: GitHub.

Appendix: source

Thrown at crates/fresh-editor-core/src/config_io.rs:1066

    /// User's downloads directory (for file open dialog shortcuts)
    pub downloads_dir: Option<std::path::PathBuf>,
}

impl DirectoryContext {
    /// Create a DirectoryContext from the system directories
    /// This should ONLY be called from main()
    pub fn from_system() -> std::io::Result<Self> {
        let data_dir = dirs::data_dir()
            .ok_or_else(|| {
                std::io::Error::new(
                    std::io::ErrorKind::NotFound,
                    "Could not determine data directory",
                )
            })?
            .join("fresh");

        let config_dir = Self::default_config_dir().ok_or_else(|| {
            std::io::Error::new(
                std::io::ErrorKind::NotFound,
                "Could not determine config directory",
            )
        })?;

        Ok(Self {
            data_dir,
            config_dir,
            home_dir: dirs::home_dir(),
            documents_dir: dirs::document_dir(),
            downloads_dir: dirs::download_dir(),
        })
    }

    /// Create a DirectoryContext for testing with a temp directory
    /// All paths point to subdirectories within the provided temp_dir
    pub fn for_testing(temp_dir: &std::path::Path) -> Self {
        Self {

View on GitHub (pinned to 67894ca546)