Zackriya-Solutions/meetily · error · anyhow::Error

Could not find config directory

Error message

Could not find config directory

What it means

dirs::config_dir() returned None while resolving the path for notifications.json (config dir then meetily/notifications.json). The platform lookup for the user's config directory failed - on Linux that means no absolute XDG_CONFIG_HOME and no HOME; on macOS/Windows the home/profile directory is unavailable.

Source

Thrown at frontend/src-tauri/src/notifications/settings.rs:116

    #[allow(dead_code)] // Reserved for future functionality
    app_handle: AppHandle<R>,
    settings_path: PathBuf,
}

impl<R: Runtime> ConsentManager<R> {
    pub fn new(app_handle: AppHandle<R>) -> Result<Self> {
        let settings_path = Self::get_settings_path()?;

        Ok(Self {
            app_handle,
            settings_path,
        })
    }

    /// Get the path where notification settings are stored
    fn get_settings_path() -> Result<PathBuf> {
        let mut path = dirs::config_dir()
            .ok_or_else(|| anyhow!("Could not find config directory"))?;

        path.push("meetily");
        path.push("notifications.json");

        // Ensure parent directory exists
        if let Some(parent) = path.parent() {
            std::fs::create_dir_all(parent)?;
        }

        Ok(path)
    }

    /// Load notification settings from disk
    pub async fn load_settings(&self) -> Result<NotificationSettings> {
        if !self.settings_path.exists() {
            log_info!("No notification settings file found, using defaults");
            return Ok(NotificationSettings::default());
        }

View on GitHub (pinned to 0281737d87)

Solutions

  1. Run the app in a normal user session, or set HOME (and a valid XDG_CONFIG_HOME) in the service unit
  2. Inside a Tauri app, prefer app.path().app_config_dir() over the dirs crate - it resolves via the app handle
  3. Fail with an actionable message naming the missing environment variable

Example fix

// before
let mut path = dirs::config_dir()
    .ok_or_else(|| anyhow!("Could not find config directory"))?;
path.push("meetily");
path.push("notifications.json");

// after - resolve through the Tauri app handle; resilient to env quirks
fn get_settings_path<R: tauri::Runtime>(app: &tauri::AppHandle<R>) -> Result<PathBuf> {
    let mut path = app.path().app_config_dir()
        .map_err(|e| anyhow!("Could not resolve app config dir: {e}"))?;
    path.push("notifications.json");
    if let Some(parent) = path.parent() {
        std::fs::create_dir_all(parent)?;
    }
    Ok(path)
}
Defensive patterns

Strategy: validation

Validate before calling

fn config_dir_resolvable() -> bool {
    if cfg!(target_os = "linux") {
        match std::env::var_os("XDG_CONFIG_HOME") {
            Some(v) if v.is_absolute() => true,
            _ => std::env::var_os("HOME").is_some(),
        }
    } else {
        std::env::var_os("HOME").is_some()
    }
}

Prevention

When it happens

Trigger: Running the process with a stripped environment (systemd service, cron, launchd daemon without HOME), XDG_CONFIG_HOME set to a relative (invalid) path, or a Windows user profile that failed to load.

Common situations: App auto-started by a service manager that did not set HOME/XDG variables; CI or test harnesses with minimal environments.

Related errors


AI-assisted analysis of Zackriya-Solutions/meetily@0281737d87 (2026-08-16). Data as JSON: /api/errors/6282392e5470d744. Report an issue: GitHub.