asciinema/asciinema · error

bail!(e)

Error message

bail!(e)

What it means

read_install_id reads the install-id file and wraps any filesystem error other than NotFound with bail!(e). This means an I/O problem occurred while opening or reading the install id file (install-id in the state/config directory) and asciinema surfaces the raw std::io::Error message.

Source

Thrown at src/config.rs:192

fn parse_server_url(s: &str) -> Result<Url> {
    let url = Url::parse(s)?;

    if url.host().is_none() {
        bail!("server URL is missing a host");
    }

    Ok(url)
}

fn read_install_id(path: &PathBuf) -> Result<Option<String>> {
    match fs::read_to_string(path) {
        Ok(s) => Ok(Some(s.trim().to_string())),

        Err(e) => {
            if e.kind() == ErrorKind::NotFound {
                Ok(None)
            } else {
                bail!(e)
            }
        }
    }
}

fn generate_install_id() -> String {
    Uuid::new_v4().to_string()
}

fn save_install_id(path: &PathBuf, id: &str) -> Result<()> {
    if let Some(dir) = path.parent() {
        fs::create_dir_all(dir)?;
    }

    fs::write(path, id)?;

    Ok(())
}

View on GitHub (pinned to 7749806198)

Solutions

  1. Fix permissions on the install-id file (chmod/chown) so the current user can read it
  2. If the path is wrong (e.g. a directory), delete it so asciinema can regenerate a fresh install id
  3. Check env vars ASCIINEMA_CONFIG_HOME / XDG_STATE_HOME / HOME don't point to unreadable locations

Example fix

// before
$ ls -l ~/.local/state/asciinema/install-id  # root-owned, mode 600
// after
$ sudo chown $USER ~/.local/state/asciinema/install-id && chmod 600 ~/.local/state/asciinema/install-id
Defensive patterns

Strategy: try-catch

Validate before calling

let path = state_dir.join("install-id");
if path.exists() && !path.is_file() {
    return Err(format!("{} is not a regular file", path.display()));
}

Try / catch

match std::fs::read_to_string(&install_id_path) {
    Ok(s) => Some(s.trim().to_string()),
    Err(e) if e.kind() == std::io::ErrorKind::NotFound => None,
    Err(e) => { eprintln!("cannot read install id: {e}"); std::process::exit(1); }
}

Prevention

When it happens

Trigger: Calling get_install_id when the install-id file exists but cannot be read: e.g. PermissionDenied on ~/.local/state/asciinema/install-id, IsADirectory where the file should be, or other non-NotFound io::ErrorKind values.

Common situations: Restrictive permissions after running asciinema as another user (root vs user), a directory accidentally created at the install-id path, filesystem errors on NFS/synced folders, or SELinux/AppArmor denials.

Related errors


AI-assisted analysis of asciinema/asciinema@7749806198 (2026-09-03). Data as JSON: /api/errors/c329206b7bf38dce. Report an issue: GitHub.