atuinsh/atuin · error

Could not find history file {p:?}. Try setting and exporting

Error message

Could not find history file {p:?}. Try setting and exporting $HISTFILE

What it means

is_file validates that the given path is an existing regular file before import; if not, it fails with guidance to set $HISTFILE. It is thrown when the configured history file path does not point to a readable file.

Source

Thrown at crates/atuin-client/src/import/mod.rs:107

fn get_histdir_path<D>(def: D) -> Result<PathBuf>
where
    D: FnOnce() -> Result<PathBuf>,
{
    get_histpath(def).and_then(is_dir)
}

fn read_to_end(path: PathBuf) -> Result<Vec<u8>> {
    let mut bytes = Vec::new();
    let mut f = File::open(path)?;
    f.read_to_end(&mut bytes)?;
    Ok(bytes)
}
fn is_file(p: PathBuf) -> Result<PathBuf> {
    if p.is_file() {
        Ok(p)
    } else {
        bail!("Could not find history file {:?}. Try setting and exporting $HISTFILE", p);
    }
}
fn is_dir(p: PathBuf) -> Result<PathBuf> {
    if p.is_dir() {
        Ok(p)
    } else {
        bail!("Could not find history directory {:?}. Try setting and exporting $HISTFILE", p);
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[derive(Default)]
    pub struct TestLoader {
        pub buf: Vec<History>,
    }

View on GitHub (pinned to c0c717ab04)

Solutions

  1. Set and export HISTFILE (e.g. export HISTFILE=~/.bash_history) before running the import
  2. Check the path exists with ls and correct any typo
  3. Touch/create the history file if the shell hasn't written one yet

Example fix

// before
atuin import zsh
// after
export HISTFILE=~/.zsh_history
atuin import zsh
Defensive patterns

Strategy: validation

Validate before calling

const p = std::env::var("HISTFILE").unwrap_or_default();
if p.is_empty() || !std::path::Path::new(&p).is_file() {
    eprintln!("Set HISTFILE to an existing history file before importing");
}

Type guard

fn history_file_ok(p: &str) -> bool {
    std::path::Path::new(p).is_file()
}

Try / catch

match is_file(path) {
    Ok(p) => import(p),
    Err(e) => eprintln!("{e}; export HISTFILE=~/.bash_history and retry"),
}

Prevention

When it happens

Trigger: Running 'atuin import' (e.g. auto, zsh, bash) with a history file path that is missing, a directory, or misdetected — e.g. HISTFILE unset so a default path doesn't exist.

Common situations: Fresh shell where $HISTFILE isn't exported; typo'd path passed to import; history file not yet created by the shell.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of atuinsh/atuin@c0c717ab04 (2026-09-12). Data as JSON: /api/errors/580b714f3ade8b1d. Report an issue: GitHub.